On my local machine, I want to deploy static Web pages (containing HTML, CSS, JS files) on Node, without using any framework (e.g., Express). I did put the Web page related files into the public folder, and then call the index.html, by using the fs library in node, as the following:
var http = require('http'), fs = require('fs');
fs.readFile('./public/index.html', function (err, html) {
if (err) { throw err;}
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html); response.end();
}).listen(1337, '127.0.0.1');;
});
I used CURL and all the files (HTML, CSS, JS) are in fact deployed on the localhost. However, when I go to the port 1337 on the localhost, it shows the HTML contents but doesn't show the behavior, written in JS, imported in the index.html.