I have a simple site:
const express = require("express");
const app = express();
app.set("view engine", "hbs");
app.get("/about-me", function(_, response) {
response.render("about_me.hbs");
});
app.get("/", function (_, response) {
response.render("index.hbs");
});
app.all(/.*/, function (_, response) { // 404 page
response.sendStatus(404);
response.send("<h1>404 Not Found</h1>");
}
app.listen(3000);
But when I opened http://localhost:3000/not-exist , there was "Not Foun<" text. Why it’s happening and how to fix it?
>Solution :
You can’t send two responses to a single request.
Use sendStatus or send.
If you want to control the status code when you use send, use status.