To generate HTML with Node.js, we call the createServer
method.
For instance, we write
const http = require("http");
http
.createServer((req, res) => {
res.write("<html><head></head><body>");
res.write("<p>Write your HTML content here</p>");
res.end("</body></html>");
})
.listen(1337);
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.