Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Forked from bnoordhuis/gist:702695
Created January 9, 2013 10:09
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 gotomypc/4492058 to your computer and use it in GitHub Desktop.
Save gotomypc/4492058 to your computer and use it in GitHub Desktop.
http = require('http');
fs = require('fs');
fd = fs.openSync(__filename, 'r');
size = fs.fstatSync(fd).size;
server = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Length': size,
'Content-Type': 'text/plain'
});
res._send(''); // force flush
fs.sendfile(req.connection.fd, fd, 0, size, function(err, n) {
console.log(arguments);
res.end();
});
});
console.log("Starting server.");
server.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment