Created
February 1, 2014 01:41
-
-
Save lengstrom/8746722 to your computer and use it in GitHub Desktop.
Simple node.js static http file server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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