Categories
JavaScript Answers

How to fix Error: Cannot GET / witn Node Express?

Spread the love

To fix Error: Cannot GET / witn Node Express, we add render a template or expose a static folder.

For instance, we write

app.use(express.static(__dirname + "/public"));

app.get("/", (req, res) => {
  res.render("index.ejs");
});

to call app.use with the middleware returned by express.static to expose the /public folder as a static files folder.

We also add a get / route to render the index.ejs template.

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 *