Skip to content

Instantly share code, notes, and snippets.

@stevenklise
Created September 13, 2012 22:47
Show Gist options
  • Save stevenklise/3718300 to your computer and use it in GitHub Desktop.
Save stevenklise/3718300 to your computer and use it in GitHub Desktop.
Simple static file serving with Node.js
{
"name": "node-static-test",
"version": "0.0.1",
"engines": {
"node": "0.8.x"
},
"dependencies" : {
"http": "latest",
"node-static": "latest"
}
}
// download these files
// If you're running node 0.8.x, run `$ npm install`
// Then `$ node server.js`
var http = require('http');
var static = require('node-static');
http.createServer(function(request,response) {
var file = new static.Server('./public', {
cache: false
});
request.addListener('end', function() {
file.serve(request, response);
});
}).listen(1337,'0.0.0.0');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment