Last active
August 29, 2015 14:17
-
-
Save mhoyer/108f939fb27e5631eacf to your computer and use it in GitHub Desktop.
Tiny, simple HTTP server
This file contains 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
// run with `node httpserve.js` and go to shown url | |
var http = require('http'), | |
path = require('path'), | |
fs = require('fs'); | |
var webroot = __dirname, | |
port = 8080; | |
http.createServer(function(req, res) { | |
var url = req.url; | |
console.log(req.method + ' ' + url); | |
if (url == undefined || url == '' || url == '/') url = 'index.html'; | |
fs.readFile(path.join(webroot, url), function(err, data) { | |
res.writeHead(200); | |
res.end(data); | |
}); | |
}).listen(port); | |
console.log('HTTP at http://localhost:' + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment