Skip to content

Instantly share code, notes, and snippets.

@ShawnHymel
Last active May 15, 2016 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShawnHymel/e6f9ff2aca7130b69c0d61de33d5e59e to your computer and use it in GitHub Desktop.
Save ShawnHymel/e6f9ff2aca7130b69c0d61de33d5e59e to your computer and use it in GitHub Desktop.
SimpleServer
/**
* Simple web server based on
* http://expressjs.com/en/starter/hello-world.html
*
* Prerequisites:
* - Node
* - Express (npm install express)
*
* To use, save as a file (e.g. SimpleServer.js) and run with:
* node SimpleServer.js /PATH/TO/WWW/
*/
// Parameters
var sitePath = process.argv[2] || ".";
var port = 4242;
// Libraries
var express = require('express');
var app = express();
// Request logging
app.use(function(req, res, next) {
console.log(req.url);
next();
});
// Start server
console.log(sitePath);
console.log("Starting server in: " + __dirname + '/' + sitePath);
app.use(express.static(__dirname + '/' + sitePath));
app.listen(port, function() {
console.log("Server running at: http://localhost:" + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment