Last active
December 15, 2015 19:28
-
-
Save piscis/5311077 to your computer and use it in GitHub Desktop.
Copy&Paste static file server with nodejs
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
/** | |
* 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