To fix the ‘Error: Cannot GET /’ error 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.html");
});
to call app.get
with '/'
and the route handler to handle GET requests to the /
route.
In the route handler for the GET / route, we call res.render
to render the index.html template on the screen.