statik

Simple static file server – serve any directory over HTTP

Statik

A simple and easy-to-use Node.js module to server static files over HTTP. It's super simple to use it.

$ npm install -g statik
$ cd ~/Sites
$ statik

Then head to http://localhost:3000/ to see the contents of ./public served over HTTP.

// Start server at http://localhost:3000 serving ./public
$ static --port 3000
 
// Start server at http://localhost:3000 serving ~/Sites/project
$ statik --port 3000 ~/Sites/project
  • maxAge: browser cache maxAge in milliseconds. Defaults to 0
  • hidden: allow transfer of hidden files. Defaults to false
  • redirect: redirect to trailing "/" when pathname is directory. Defaults to true
  • compress: enable gzip compression. Defaults to true
  • verbose: enable logging to stdout. Defaults to false
$ npm install statik --save
// app.js 
var statik = require('statik');
statik(3000);

Your server will be running on http://localhost:3000/ serving ./public directory.

You can specify the directory you wish to serve as an argument.

// app.js 
var statik = require('statik');
statik({
    port: 3000,
    root: '/Users/hongymagic/Sites'
});

Your server will be running on http://localhost:3000/ server /Users/hongymagic/sites directory.

You can also use command line options when invoking statik function.

$ echo 'web: node app.js' > Procfile
$ heroku create --stack cedar statik-app
$ git push heroku master
$ heroku open

BAM!

Because I hate file:// protocol for the reasons I wish not to disclose. One of the recent ones I've come across is Typekit. And trust me there are other problems that pop-up if you're primarily working for the http:// protocol.

There are some default HTTP Headers that I am going to introduce for the reaons why I have create this package in the first place:

  1. Content-Type: statik uses another internal Node.js package mime to check against content types
  2. Cache-Control: 'no-cache'. The primary purpose of statik was so I could easily run a folder as web server over HTTP while I'm working on a new site. Might as well kill off the cache while I'm writing and debugging CSS and JavaScript. There will be an option to disable to default behaviour though.

For now, it will translate that into index.html

  1. Clean up code around 404 and 500 errors
  2. Options to add/remove default HTTP headers
  3. Default set of files instead of index.html