Skip to content

Instantly share code, notes, and snippets.

@lengstrom
Created February 1, 2014 01:41
Show Gist options
  • Save lengstrom/8746722 to your computer and use it in GitHub Desktop.
Save lengstrom/8746722 to your computer and use it in GitHub Desktop.
Simple node.js static http file server
var app = require('http').createServer(handler), fs = require('fs');
var port = Number(process.env.PORT || 5000);
app.listen(port, function() {
console.log("Listening on " + port);
});
function handler(req, res) {
fs.readFile(__dirname + req['url'], function(err, data) {
if (err) {
res.writeHead(200);
res.end("File not found!");
return;
}
res.writeHead(200);
res.end(data);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment