JavaScript Answers

How to generate HTML with Node.js?

Spread the love

To generate HTML with Node.js, we call the createServer method.

For instance, we write

const http = require("http");

  .createServer((req, res) => {
    res.write("<p>Write your HTML content here</p>");

to call createServer with a callback that calls res.write to write HTML as the response body.

We call res.end to finish writing the response body.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.