Skip to content

Instantly share code, notes, and snippets.

@appleton
Created January 29, 2012 17:48
Show Gist options
  • Save appleton/1699813 to your computer and use it in GitHub Desktop.
Save appleton/1699813 to your computer and use it in GitHub Desktop.
Serve a static site from node.js handy for local development
var http = require('http'),
fs = require('fs');
http.createServer(function(req, res){
var path = (req.url === '/' ? './index.html' : '.' + req.url);
fs.readFile(path, 'utf-8', function(err, data){
if(!err){
console.log('Serving: ', req.url);
res.writeHead(200);
res.end(data);
}else{
console.log('Not found: ', req.url);
res.writeHead(404);
res.end();
}
});
}).listen(1337);
console.log('Server running at http://127.0.0.1:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment