Categories
JavaScript Answers

How to change Express view folder based on where is the file that res.render() is called with Node.js?

Spread the love

To change Express view folder based on where is the file that res.render() is called with Node.js, we call the res.render method with the template path.

For instance, we write

app.get("/your/path", (req, res) => {
  res.render(__dirname + "/folder/with/views/viewname");
});

to call res.render with the path to the template as in the route handler for the /your/path route.

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 *