Skip to content

Instantly share code, notes, and snippets.

@ayoayco
Created March 3, 2017 06:33
Show Gist options
  • Save ayoayco/06d45c2c68b05587b4008f244494543d to your computer and use it in GitHub Desktop.
Save ayoayco/06d45c2c68b05587b4008f244494543d to your computer and use it in GitHub Desktop.
//requires node modules: "connect" and "serve-static"
var connect = require('connect');
var serveStatic = require('serve-static');
function printUsageAndExit() {
console.log("Usage:");
console.log("node webserver.js <port> \"<path>\"");
console.log("Examples:");
console.log("node webserver.js 8080 \"../\"");
console.log("node webserver.js 80 \"C:/Web/MyApplication\"");
process.exit();
}
var args = process.argv;
if (args.length != 4) {
printUsageAndExit();
}
var port = args[2];
var path = args[3];
console.log('Starting web server at localhost:' + port + " for directory \"" + path + "\"");
connect().use(serveStatic(path)).listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment