To render basic HTML view with JavaScript, we use Express.
For instance, we write
const express = require("express");
const app = express.createServer();
app.set("view options", { layout: false });
app.use(express.static(__dirname + "/public"));
app.get("/", (req, res) => {
res.render("index.html");
});
app.listen(8080, "127.0.0.1");
to call app.get
with the URL for the route and the route handler.,
In it, we call res.render
to render index.html to the user.
index.html is in the /public folder of the project since we call express.static
with __dirname + "/public"
to make __dirname + "/public"
the static file path.