Skip to content

Instantly share code, notes, and snippets.

@korya
Created June 26, 2014 14:18
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 korya/4e2a8ebd57eb3f9ea719 to your computer and use it in GitHub Desktop.
Save korya/4e2a8ebd57eb3f9ea719 to your computer and use it in GitHub Desktop.
Quick Node.js webserver for serving static content

Many times I need just to run a simple webserver in a specific directory. That is the solution I came up with.

Installation

Put the files somewhere and then:

$ npm install

Usage

$ node server.js [<PATH TO DIR> [<PORT>]]
{
"name": "quick-static-server",
"description": "Quick webserver for serving static files in any dir",
"version": "0.0.1",
"author": "korya <korya@github.com>",
"dependencies": {
"express": "3.x"
},
"engines": {
"node": ">=0.10"
}
}
var express = require('express'),
app = express()
var dir = process.argv[2] || __dirname + '/static'
var port = process.argv[3] || process.env.SERVER_PORT || 8080
app.use(express.static(dir))
app.use(express.directory(dir))
app.listen(port)
console.log('Listening on', port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment