Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created October 12, 2014 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhoff/4f768bdd3af4c5401e6c to your computer and use it in GitHub Desktop.
Save alanhoff/4f768bdd3af4c5401e6c to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
require('http').Server(function(req, res) {
if (!fs.existsSync(req.url)) {
res.statusCode = 404;
res.end();
}
var name = path.basename(req.url);
res.writeHead(200, {
'Content-Disposition': 'attachment; filename="' + name + '"'
});
fs.createReadStream(req.url).pipe(res);
}).listen(8888);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment