Skip to content

Prestaul/stackr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stackr

A simple http module system for node.js applications, similar to connect, or the more basic stack.

Stackr does not supply any middleware, it just provides an easy interface for composing a middleware stack.

Basic Usage

Stackr can be required like any other node module:

var stackr = require('stackr');

You can construct a stack by passing middleware to the stackr constructor as arguments:

var stack = stackr(
    require('logger')(),
    require('static')(root, mount)
);

or by calling use on the stack:

var stack = stackr()
    .use(require('logger')())
    .use(require('static')(root, mount));

Creating a Server

Your stack can be used to create an http server:

require('http').createServer(stackr(
    require('logger')(),
    require('static')(root, mount)
)).listen(1337);

Using Substacks

Substacks provide a simple way to compose more complex stacks:

var substack = stackr.substack(
    require('logger')()
);

var stack = stackr(
    substack,
    require('auth')()
);

substack.use(require('static')(root, mount));

In the above example the execution order will be logger, static, then auth because the entire substack will execute before anything that follows it in the outer stack.

About

A simple http module system for node.js applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published