const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = 4002; const ROOT = __dirname; const mime = { '.html': 'text/html', '.css': 'text/css', '.js': 'text/javascript', }; http.createServer((req, res) => { const urlPath = req.url === '/' ? '/index.html' : req.url; const file = path.join(ROOT, urlPath); fs.readFile(file, (err, data) => { if (err) { res.writeHead(404); res.end('Not found'); return; } const ext = path.extname(file); res.writeHead(200, { 'Content-Type': mime[ext] || 'text/plain' }); res.end(data); }); }).listen(PORT, () => { console.log(`Anki FC Creator running at http://localhost:${PORT}`); });