const http = require('http'); const fs = require('fs'); const server = http.createServer((req, res) => { //console.log(req) fs.readFile('./'+req.url, (err, data) => { if(err){ res.writeHead(404, "Not Found"); res.write("No file found"); res.end(); } else { res.writeHead(200, { 'Content-Length': data.length, 'Content-Type': 'text/html' }) res.write(data); res.end(); } }); }); server.on('clientError', (err, socket) => { socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); }); server.listen(8088, () => { console.log("listen on http://localhost:8088/"); });