Skip to content

Instantly share code, notes, and snippets.

@piscis
Last active December 15, 2015 19:28
Show Gist options
  • Save piscis/5311077 to your computer and use it in GitHub Desktop.
Save piscis/5311077 to your computer and use it in GitHub Desktop.
Copy&Paste static file server with nodejs
/**
* Create a static file server
* requires: node-static
* example: npm install node-static
*/
var conf = {
port: 8080,
address: "0.0.0.0",
pubDir: __dirname,
options: {
cache: 0
}
};
var srv = require('node-static'),
file = new srv.Server(conf.pubDir, conf.options);
require('http').createServer(function (request, response) {
request.addListener('end', function () {
file.serve(request, response);
});
}).listen(conf.port,conf.address);
console.log('Server started: '+conf.address+':'+conf.port);
console.log('PubDir: '+conf.pubDir);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment