want to make 2 pages ,1 balance ,1 deposit .that i go into the 2 pages ,and i can do changes on the account in the json like i go into the "balance "page ,select 1 account ,and i can add balance in it ,and save it to the json how can i made a nodejs app and webpage
account.json
"1000001": {
"accountType": "Chequing",
"accountBalance": 0
},
"1000002": {
"accountType": "Savings",
"accountBalance": 0
},
"1000011": {
"accountType": "Chequing",
"accountBalance": 0
},
"1000022": {
"accountType": "Savings",
"accountBalance": 0
},
"1000031": {
"accountType": "Chequing",
"accountBalance": 0
},
"1000032": {
"accountType": "Savings",
"accountBalance": 0
},
"1000051": {
"accountType": "Chequing",
"accountBalance": 13.699999999999989
},
"1000052": {
"accountType": "Savings",
"accountBalance": 0
},
"1000071": {
"accountType": "Chequing",
"accountBalance": 0
},
"1000081": {
"accountType": "Savings",
"accountBalance": 0
},
"1000091": {
"accountType": "Chequing",
"accountBalance": 0
},
"lastID": "1000091"
}
-------
var express = require('express');
var exphbs = require('express-handlebars');
var app = express();
//app.engine('.hbs', exphbs({extname: '.hbs'}));
//app.set('view engine', '.hbs');
app.engine('hbs', exphbs({defaultLayout: false, extname:'.hbs',}));
const bodyParser = require("body-parser");
const fs = require("fs");
var createError = require("http-errors");
const passport = require("passport");
var path = require("path");
const session = require("express-session");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var express = require('express');
var exphbs = require('express-handlebars');
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(express.static("./public"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var userLogin = {};
app.post("/api/login", (req, res) => {
fs.readFile("./data.json", (err, data) => {
var arr = [];
if (err) {
console.log(err);
} else {
if (data.toString()) {
arr = JSON.parse(data.toString());
}
var s = arr.find((item) => {
if (item.name == req.body.name) {
return item;
}
});
if (s) {
if (s.password == req.body.password) {
userLogin = req.body;
res.json({
status: "y",
meg: "login success",
data: s.name,
});
} else {
res.json({
status: "err",
meg: "wrong password ",
});
}
} else {
res.json({
status: "n",
meg: "no such user ",
});
}
}
});
});
app.get("/index", (req, res) => {
if (userLogin.name) {
res.render("index", { username: userLogin.name });
}
else {
res.render("login");
}
});
app.post("/logout", (req, res) => {
res.render('login', {
});
});
app.post("/returnBank", (req, res) => {
res.render('lndex', {
});
});
app.post('/withdrawal', (req, res) => {
});
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "public")));
app.post("/back", (req, res) => {
var someData = {
user: req.MySession.user,
accounts: userAccountsOnly
};
res.render('lndex', {
data: someData
});
});
var PORT = 3000;
app.listen(3000, function () {
console.log(`Listening on port ${PORT}`);
});
-------------------
i want to make 2 pages ,1 balance ,1 deposit .that i go into the 2 pages ,and i can do changes on the account in the json
like i go into the "balance "page ,select 1 account ,and i can add balance in it ,and save it to the json
how can i made a nodejs app and webpage
Step by step
Solved in 2 steps