how to fix this problem in node js ? (node:41392) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated (Use `node --trace-deprecation ...` to show where the warning was created) GET / 304 20.330 ms - - GET /css/styles.css 404 1.535 ms - 27 GET /images/1.png 404 1.321 ms - 25 POST /login 404 16.736 ms - 19 login.hbs login file login Email address Password Login Register ---------------- index .hbs       Total Balance   Deposit Deposit   Withdraw Withdraw     -------------------------------- app.js const express = require("express"); const app = express(); 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"); 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.get("/", (req, res) => { res.render("login"); }); var PORT = 3000; app.listen(3000, function () { console.log(`Listening on port ${PORT}`); }); ---------------- users.json [{"name":"swf@1.com","password":"123"}, {"name":"123","password":"111"}, {"name":"1234","password":"1234"} {"name":"134@2.com","password":"122234"}] ]   ---------- i want to login to the index.hbs ,i enter the username and password in the json ,and it shows Cannot POST /login

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter6: Managing Multiple Worksheets And Workbooks
Section: Chapter Questions
Problem 18RA
icon
Related questions
Question

how to fix this problem in node js ?

(node:41392) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is
deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
GET / 304 20.330 ms - -
GET /css/styles.css 404 1.535 ms - 27
GET /images/1.png 404 1.321 ms - 25
POST /login 404 16.736 ms - 19

login.hbs

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="/css/styles.css">
<title> login file </title>
</head>
<body>
<div class="jumbotron jumbotron-fluid bannerTop py-4">
<div id="header-div"class="container">
<img src="/images/1.png" alt="logo">
<h3>login </h3>
</div>
</div><div class="container p-3 my-3 border">
<form method="post" action="/login">
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
</div>
<section class="mb-4">
<button type="submit" class="btn btn-outline-dark">Login</button>
<a class="btn btn-outline-dark" href="/register" role="button">Register</a>
</section>
</form>
</div>

</body>
</html>
----------------
index .hbs

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="./data/l.css">

</head>

 

<body>

<div class="flex">

<div class="element-center">

 

<div id="acctBalance">

 

<span class="wrap"></span>

</a>

<h1>

Total Balance

</h1>

<label id="acctBalanceLbl"></label>

</div>

 

<div id="inputs">

<h2>

Deposit

</h2>

<input type="text" id="userDeposit" required>

<button id="btnDeposit">Deposit</button>

 

<h2>

Withdraw

</h2>

<input type="text" id="userWithdraw" required>

<button id="btnWithdraw">Withdraw</button>

</div>

</div>

</div>

 

<script type="text/javascript" src="bank_account_script.js"></script>

<script type="text/javascript" src="typewriter_script.js"></script>
<script src="./data/2.js."></script>

</body>

 

</html>


--------------------------------

app.js

const express = require("express");
const app = express();
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");
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.get("/", (req, res) => {
res.render("login");
});

var PORT = 3000;
app.listen(3000, function () {
console.log(`Listening on port ${PORT}`);
});

----------------
users.json
[{"name":"swf@1.com","password":"123"},
{"name":"123","password":"111"},
{"name":"1234","password":"1234"}
{"name":"134@2.com","password":"122234"}]

]

 

----------

i want to login to the index.hbs ,i enter the username and password in the json ,and it shows

Cannot POST /login

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning