localm / serve.js
Gemini AI
feat: Add Node.js static file server and update package.json
f9686da
raw
history blame
614 Bytes
const http = require('http'), fs = require('fs'), path = require('path');
http.createServer((req, res) => {
const file = '.' + (req.url === '/' ? '/index.html' : req.url);
fs.readFile(file, (err, data) => {
if (err) {
res.writeHead(404);
return res.end(String(err));
}
const ext = path.extname(file);
const contentType = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css'
}[ext] || 'text/plain';
res.writeHead(200, { 'Content-Type': contentType });
res.end(data);
});
}).listen(8000, () => console.log('Serving on port 8000'));