Skip to content
creationix edited this page Jan 3, 2011 · 2 revisions

Community Modules

Stack is a super-simple middleware router. It takes in as arguments a list of request handlers that punt control to the next layer via a third next() callback for cases where they would return 404 to the client. For errors, they call next(err) instead of 500. Other than that, they are vanilla node.js http request handlers. Stack takes these handlers and chains them up at server startup but does not provide any handlers on it's own. Note that this is the same module format as Connect and most modules should be usable in either.

This page is to list any community supplied request handlers that follow this spec. For each module, provide the npm package name, and a sample usage including an inline require.

The creationix collection

A collection of stack compatable modules for my personal use. You are free to use these, but I don't support them (not yet at least).

Can be installed via npm install creationix.

Source at http://github.com/creationix/creationix

// This is a sample http server just to show context of the stack layers
// It's not required for every example on this page.
require('http').createServer(require('stack')(

  // Log HTTP requests to stdout
  require('creationix/log')(),

  // Requires http basic auth for everything after this (I normally store the data in a separate file and use require to load it.
  require('creationix/auth')({creationix: "hashedpasswordhere"}),

  // Provides JSON file listings (like for a file browser)
  require('creationix/listing')('/files', '/home'),

  // Serves static resources using streams
  require('creationix/static')('/', '/home/tim/www', 'index.html'),

  // A custom route.  This is like connect's router layer, but MUCH simpler.
  require('creationix/mount')("GET", "/users", function (req, res, next) { 
    // Do something custom here, maybe send back a json list of users
  })

)).listen(8080);

Clone this wiki locally