Categories
JavaScript Answers

How to send HTML file to client with Node?

Spread the love

To send HTML file to client with Node, we call the sendFile method.

For instance, we write

const app = express();

app.get("/test", (req, res) => {
  res.sendFile("views/test.html", { root: __dirname });
});

to call res.sendFile with the template’s path to render the template.

root is the root folder for the template files.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.