Last active
May 15, 2016 17:49
-
-
Save ShawnHymel/e6f9ff2aca7130b69c0d61de33d5e59e to your computer and use it in GitHub Desktop.
SimpleServer
This file contains 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
/** | |
* 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