node package manager



Automatically serve static files, with version control (etag supported), compression and CDN support. This makes it possible to skip all the annoying packaging process when deploying your application.

You may also want to try a inline static management module.


var express = require('express');
var autostatic = require('autostatic');
var app = express();
var as = autostatic({
  root: '',
  dir: __dirname + '/public'
app.use(express.static(__dirname + '/public'));
  static: as.helper(),

In template:

<script src="${static('/js/abcd.js')}"></script>

this will output as:

<script src=""></script>

The abcd.min.js file is generated by this module automatically. This is an asynchronous process, so it will serve the original /js/abcd.js first, and cache control is handled by express.static middleware. Once the minified version of this file is ready, minified file with etag as suffix (/js/abcd.min.js?122456-123) will be served.

You can set up a unique domain for your assets (, in Nginx or Apache, with your public files directory as root (in Nginx) or DocumentRoot (in Apache).

Or, set up an upload method to deploy the compressed file to CDN:

var as = autostatic({
  root: '',
  upload: function(path, contents) {
    // your upload method 

Concatenating files

You can use autostatic to serve multiple static files.

<script src="${static('/js/abcd.js', '/js/efgh.js')}"></script>

will output:

<script src="/autostatic??/js/abcd.js,/js/efgh.js"></script>

The path /autostatic can be configured:

  route: '/serve_assets'