This post was written for Nodejitsu blog and is crossposted here. Nodejitsu loved what I was doing at and is now supporting the project.

The middleware architechture is strange beast. On one hand everybody knows about it and knows how to use it. On the other hand, it seems there are only a handful of modules that take advantage of it.

ware (GitHub: segmentio/ware, License: MIT) is a poster child for a Node.js module. It’s just about 80 lines large, maintained by abunch of folks at Segment, has 10k daily downloads and just under 100 stars on GitHub. It’s sole purpose is to help you easily create your own middleware layer.

npm install ware


The API is very straight forward, in fact lets make something that looks like Express.js

var ware = require('ware');
var app = ware();

app.use(function(req, res, next) {
  if (! {
    return next(new Error('Missing `name`.'));

  res.x = 'Hello ' +;
  setTimeout(next, 50);

app.use(function(req, res, next) {
  res.y = '[' + res.x + ']';
});{name: 'Alex'}, {}, function(err, req, res) {
});{}, {}, function(err, req, res) {

There’s also a built in support for generators (on the server for now).

var ware = require('ware');

var middleware = ware()
  .use(function(obj) {
    obj.url = '';
  .use(function *(obj) {
    obj.src = yield http.get(obj.url);
  });{ url: '' }, function(err, obj) {
  if (err) throw err;
  obj.src // "obj.url" source

What Else?

Checkout the runnable example and github example repository.