Is there Node.js ready-to-use tool (installed with npm
), that would help me expose folder content as file server over HTTP.
Example, if I have
If that's all you need, try this:
const http = require('http');
const fs = require('fs');
const port = 3000;
const app = http.createServer((req,res) => {
res.writeHead(200);
if (req.url === '/') req.url = '/index.html'; // courtesy of @JosephCho
res.end(fs.readFileSync(__dirname + req.url));
});
app.listen(port);
note: You need to use "/index.html" as part of your address ie "http://localhost:3000/index.html"