node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »


Koa File Server

NPM version build status Test coverage Gittip

An opinionated file server. Designed to sit behind a CDN.

  • sha256 etags and consequential 304s
  • Caches fs.stat() calls
  • Caches etag calculations
  • OPTIONS and 405 support
  • index.html files
  • Optionally serve hidden files
  • Caches gzipped versions of files
  • SPDY Push support

Does not support:

  • Dynamic files - assumes static files never change. You will have to delete files from the cache yourself if files change.
  • Directory listing
  • Path decoding


var Koa = require('koa')
var app = new Koa()

Options are:

  • root <process.cwd()> - root directory. nothing above this root directory can be served
  • maxage - cache control max age
  • etag - options for etags
    • algorithm - hashing algorithm to use
    • encoding - encoding to use
  • index - serve index.html files
  • hidden - show hidden files which leading .s
  • push - will automatically try and use server push
  • files [] - array of files (relative to root) to be server pushed
  • pushOptions {} - options to be passed to spdy push method (e.g. priority)
    • The only pushOption is priority: 1-7.
  • link - will set link headers based on files option