sirs. I am trying understand ExpressJS. I want to send simple object from express server but it just logs cannot get on screen.
app.get("/", (req, res, next) => {
console.log("middleware");
const error = true;
if (error) {
next();
}
});
app.use((err, req, res, next) => {
res.status(400).json({ error: "error description" });
});
In this code i simulated if error happens send object but it just sends cannot get. In POSTMAN body section, i just see html code with cannot get. What happening here? Can you please explain me?
In POSTMAN i can just get this HTML code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>