node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey ยป



Static file middleware for Stack. It supports HTTP Conditional GET with ETags and file modification dates, and Range requests.


You can place the middleware directly in a Stack server:

var Static = require('stack.static')
  Static(rootPath, {"default": "index.html"}),

You can serve a file manually without using Stack too:

var Static = require('stack.static')
http.createServer(function(req, res) {
  Static.serve(rootPath + req.url, req, res, 
    function(err) {
      if(err) { ... 404! ... }

You can probably replace the serve() function with your own implementation if you want to serve files from somewhere else (S3, GridFS, whatevs).

You can set default headers that get set on every response:

var Static = require('stack.static')
Static.defaultHeaders['cache-control'] = 'public'

You can override the global default handlers in each Static handler too:

var Static = require('stack.static')
    { "default": "index.html"
    , "headers": 
      { "cache-control": "public"


npm install simple-mime
npm install stack.static


All code is written in Coffee Script and converted to javascript as it's published to npm.

For normal development, all you need to be concerned about is testing:

$ make test

If you need to generate javascript for production purposes and don't want to use npm packages, you can use:

$ make generate-js
$ make remove-js

You can also have coffeescript watch the src directory and generate javascript files as they're updated.

$ make dev