Skip to content

Instantly share code, notes, and snippets.

@joaoneto
Created July 26, 2013 00:29
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 joaoneto/6085097 to your computer and use it in GitHub Desktop.
Save joaoneto/6085097 to your computer and use it in GitHub Desktop.
This gist is to climb a static server, with just one command, to test the examples of several projects that need a web server. Usage: $ npm install express; curl -ks https://gist.github.com/joaoneto/6085097/raw/761598ddb44f390179617702740fe7fbf62f6187/demo.js | node
var express = require('express'),
app = express(),
port = process.argv[2] || process.env.PORT || 9000,
webroot = process.argv[3] || process.env.WEBROOT || './demo';
app
.use(express.bodyParser())
.use(express.cookieParser())
.use(app.router)
.use(express.static(__dirname + '/' + webroot))
.listen(port, function () { console.log('Demo is running on: http://localhost:' + port); });
@joaoneto
Copy link
Author

Default usage:

$ npm install express; curl -ks https://gist.github.com/joaoneto/6085097/raw/761598ddb44f390179617702740fe7fbf62f6187/demo.js | node

Changing PORT:

$ npm install express; curl -ks https://gist.github.com/joaoneto/6085097/raw/761598ddb44f390179617702740fe7fbf62f6187/demo.js | PORT=8080 node

Changing WEB_ROOT folder:

$ npm install express; curl -ks https://gist.github.com/joaoneto/6085097/raw/761598ddb44f390179617702740fe7fbf62f6187/demo.js | WEBROOT=./public node

Changing PORT and WEB_ROOT:

$ npm install express; curl -ks https://gist.github.com/joaoneto/6085097/raw/761598ddb44f390179617702740fe7fbf62f6187/demo.js | PORT=8080 WEBROOT=./public node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment