I have a school project that I am working on, and I’m planning to use Node.js to host it. The thing is, every time I try to run it, it returns nothing.
I have 4 HTML, 2 CSS, and 2 JS files in one folder, and I’m trying to host all the HTML files.
My node.js script:
`var http = require(‘http’);
var fs = require(‘fs’);
const PORT=8080;
fs.readFile(‘./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(PORT);
})`
But the terminal doesn’t return anything.
New contributor
Hotroos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.