const http = require("http"); const fs = require("fs"); const path = require("path"); const PORT = 8000; const MIME_TYPES = { ".html": "text/html", ".css": "text/css", ".js": "text/javascript", ".ico": "image/x-icon", ".svg": "image/svg+xml", ".ttf": "font/ttf", }; http .createServer((req, res) => { let filePath = req.url === "/" ? "/index.html" : req.url; filePath = path.join(__dirname, filePath); const ext = path.extname(filePath); const contentType = MIME_TYPES[ext] || "application/octet-stream"; fs.readFile(filePath, (err, data) => { if (err) { res.writeHead(404); res.end("Not found"); return; } res.writeHead(200, { "Content-Type": contentType }); res.end(data); }); }) .listen(PORT, () => { console.log(`Serving at http://localhost:${PORT}`); });