node package manager
Loosely couple your services. Use Orgs to version and reuse your code. Create a free org »


everyware is a tiny experimental Q promise middleware library. It is intended mainly for middleware library authors, not application developers — it could be used to implement a library like jaque, but does not replace such a library.

In everyware, just as in Q-JSGI, an application is a function of one argument (the env) which returns a response or a promise of a response. A middleware is a function of one argument (the "next" application) which returns an application.

A silly example:

function notFound(env) {
  return {status: 404, body: "not found"};
function foo(env) {
  return {status: 200, body: "foo"};
function route(url, app) {
  return function(next) {
    return function(env) {
      if (env.url == url) {
        return app(env);
      } else {
        return next(env);
// w takes an app and variadic middleware, and returns an app with the 
// middleware applied 
var w = require('everyware');
var app = w(notFound, route("/foo", foo));

everyware does not assume that the middleware stack is used for handling HTTP requests. It is meant to be reused in different contexts. The middleware pattern is useful for more than HTTP — everyware provides the basics so you can easily start using this pattern in your domain.

everyware is currently used in backbone-live to build Backbone.sync implementations using functional Q middleware.

everyware strives for simplicity over convenience. JSGI style for middleware may seem less convenient than connect style, but it is simpler.

everyware makes an additional simplifying assumption that middlewares are functions of exactly one argument, requiring another closure to pass other arguments to a middleware (url and app in the route example above). A workaround is provided by mori:

var curry = require('mori').curry;
function route(next, url, app) {
  // ... 
w(notFound, curry(route, "/foo", foo));

It is also worth noting that w is exactly the same as mori.pipeline, except that w ensures responses/errors are coerced to promises.