I wanted to serve the Disp.html file through nodejs following the code I learned through a Youtube tutorial.
const http = require("http");
const fs = require("fs");
const fileContent = fs.readFileSync("Disp.html");
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-type": "text/html" });
res.end(fileContent);
});
server.listen(80, "127.0.0.1", () => {
console.log("Listening on port 80");
});
I have created a folder in VS Code with this app.js and Disp.html as the files. Every time I run the code it displays the listing directory in place of the HTML content that I am expecting to view.
What can I do to get the expected result?