Categories
JavaScript Answers

How to fix the ‘Error: Cannot GET /’ error message with Node.js and Express?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *