I have put together a small app and using html, css and javaScript. Now I want to run this on a nodejs server. I have created a separate file for the server to start running with the following code.
var http = require('http');
var fs = require('fs');
function onRequest(request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
fs.readFile('./index.html', null, function(error, data) {
if (error) {
response.writeHead(404);
response.write('File not found');
} else {
response.write(data);
}
response.end();
});
}
http.createServer(onRequest).listen(3000, function(){
console.log("The server has started");
});
Now the html is rendering but the CSS is not rendering. Plus, the JavaScript that is linked to the html is not working. I did see this Nodejs static file. But this did not seem to make sense. Any help would be appreciated.