Skip to content
Olivier Wietrich edited this page Mar 30, 2014 · 7 revisions

plumby()

Create a plumby app.

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

It is a good practice to expose your app in order to reuse it somewhere else:

var plumby = require('plumby');
var app = module.exports = plumby();

.use

Consistent and adaptive interface to use plugins or other apps.

.use(fn[, options])

A plugin is a function with the app scope as first argument with some optional options.

app.use(function(ctx, opts){
  //do something on app
}, options);

.use(name[, app, options]);

var mail = plumby();
app.use(mail);

or

var mail = plumby();
app.use('mail', mail);

plumby(name)

Plumby expose an elegant dependency injector in order to extend or use the same features in different apps:

inject mixin

var plumby = require('plumby');
plumby.inject('foo', {
  isFoo : true,
  alert : function(){
    alert('hello world');
  }
});

var app = plumby('foo');
app.alert(); //alert hello world
app.isFoo; //true

inject plugins

var plumby = require('plumby');

//add http request and debug
plumby
  .inject('bar')
  .use(superagent())
  .use(debug());

var app = plumby('bar');
var other = plumby('bar');
Clone this wiki locally