node dirtyserve.jsThe point your browser to
http://localhost:3000/myfile.xxx
and the server will try to serve that file from the local server.
| var http = require('http') | |
| var fs = require('fs') | |
| http.createServer(function (req, res) { | |
| var filename = req.url.substring(1) | |
| if (!fs.existsSync(filename)) { | |
| res.writeHead(404) | |
| res.end(filename+' not found') | |
| return | |
| } | |
| var contents = fs.readFileSync(filename) | |
| var fileEnding = req.url.match(/\.(.+)$/)[1] | |
| res.writeHead(200, { 'Content-Type': 'text/'+ fileEnding }) | |
| res.end(contents) | |
| }).listen(3000) |