Skip to content

Instantly share code, notes, and snippets.

@8bitDesigner
Last active December 20, 2015 19:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 8bitDesigner/6187251 to your computer and use it in GitHub Desktop.
Save 8bitDesigner/6187251 to your computer and use it in GitHub Desktop.
6-Line Static file server

Simple Static file server

Handy for when working on single-page apps

Usage

  1. npm install -g server-here
  2. here (if you're in a folder with files you want to serve)

Options

here --dir [directory to load files from] --port [port to use]

#! /usr/bin/env node
var express = require('express')
, args = require('optimist').argv
, path = require('path')
, app = express()
, pathName = args.d || args.dir || './'
, port = args.p || args.port || 3000
app.use(express.static(path.join(process.cwd(), pathName)));
app.listen(port, function() {
console.log('Listening on port '+port+' serving files from '+pathName)
});
{
"name": "server-here",
"version": "0.0.0",
"description": "Starts a web server. Here. In this directory.",
"main": "index.js",
"bin": {
"here": "./index.js"
},
"dependencies": {
"express": "~3.4.0",
"optimist": "~0.6.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/6187251.git"
},
"author": "",
"license": "BSD",
"readmeFilename": "README.md",
"gitHead": "931313e904128b59674276831797a4c6b44c7b58"
}
@findzen
Copy link

findzen commented Apr 8, 2015

Hey it's more than 6 lines now ;)

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