Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Prestaul/stackr
A simple http module system for node.js applications.
https://github.com/Prestaul/stackr
Last synced: 3 days ago
JSON representation
A simple http module system for node.js applications.
- Host: GitHub
- URL: https://github.com/Prestaul/stackr
- Owner: Prestaul
- License: mit
- Created: 2014-01-17T17:31:27.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-21T21:36:12.000Z (almost 11 years ago)
- Last Synced: 2024-08-10T08:17:10.093Z (3 months ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - Prestaul/stackr - A simple http module system for node.js applications. (others)
README
stackr
======A simple http module system for node.js applications, similar to [*connect*](https://github.com/senchalabs/connect), or the more basic [*stack*](https://github.com/creationix/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:
```js
var stackr = require('stackr');
```You can construct a stack by passing middleware to the `stackr` constructor as arguments:
```js
var stack = stackr(
require('logger')(),
require('static')(root, mount)
);
```or by calling `use` on the stack:
```js
var stack = stackr()
.use(require('logger')())
.use(require('static')(root, mount));
```Creating a Server
-----------------
Your stack can be used to create an http server:
```js
require('http').createServer(stackr(
require('logger')(),
require('static')(root, mount)
)).listen(1337);
```Using Substacks
---------------
Substacks provide a simple way to compose more complex stacks:
```js
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.