I am new to node js and trying to simply serve a site containing both an html and css file. I have the below code written
var http = require('http');
var fs = require('fs');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(fs.readFileSync('./style.css', {encoding: "utf8"}));
res.write(fs.readFileSync('./index.html', {encoding: "utf8"}));
res.end();
}).listen(3000);
console.log('server running @ 3000');
This 'works' when I fire up the server meaning that I can see the site rendering while considering the css, but the css text gets written out at the bottom of my site like its embedded text inside a div tag. Can anyone explain why I am seeing this? Also since I am new to nodejs, any recommendations on serving css or JS files on my server would be greatly appreciated.