Sometimes, we want to fix the ‘Error: Cannot GET /’ message with Node.js and Express.
In this article, we’ll look at how to fix the ‘Error: Cannot GET /’ message with Node.js and Express.
How to fix the ‘Error: Cannot GET /’ message with Node.js and Express?
To fix the ‘Error: Cannot GET /’ message with Node.js and Express, we need to add the route handler for the GET / route.
For instance, we write
app.get("/", (req, res) => {
res.render("index.ejs");
});
to call app.get with '/' and the route handler to handle GET requests to the / route.
Conclusion
To fix the ‘Error: Cannot GET /’ message with Node.js and Express, we need to add the route handler for the GET / route.