boot-in-the-arse
Asynchronous bootstrapping made easy. Wait for all components/plugins to start, and then start your whole app.
boot-in-the-arse
is fully reentrant and graph-based. You can load
components/plugins within plugins, and be still sure that things will
happen in the right order.
Install
To install boot-in-the-arse
, simply use npm:
npm install boot-in-the-arse --save
Example
The example below can be found here and ran using node example.js
. It
demonstrates how to use boot-in-the-arse
to load functions /
plugins in
order.
'use strict' const boot = boot { console instance} { console process} { console }
API
boot([instance], [started])
Start a booting sequence.
instance
will be used as the first
argument of all plugins loaded and use
, after
and ready
function will be
added to that object, keeping the support for the chainable API:
const server = {} server server
Options:
expose
: a key/value property to change howuse
,after
andready
are exposed.
Events:
'error'
if something bad happens'start'
when the application starts
The boot
function can be used also as a
constructor to inherits from.
app.use(func, [opts], [cb])
Loads a functions asynchronously. The function must have the signature:
{ }
done
must be called only once.
Returns the instance on which use
is called, to support a
chainable API.
If you need to add more than a function and you don't need to use a different options object or callback, you can pass an array of functions to .use
.
boot
The functions will be loaded in the same order as they are inside the array.
app.after(func([done]), [cb])
Calls a functon after all the previously defined plugins are loaded, including
all their dependencies. The 'start'
event is not emitted yet.
boot
done
must be called only once.
Returns the instance on which after
is called, to support a
chainable API.
app.ready(func([done]))
Calls a functon after all the plugins and after
call are
completed, but befer 'start'
is emitted. ready
callbacks are
executed one at a time.
boot
done
must be called only once.
Returns the instance on which ready
is called, to support a
chainable API.
boot.express(app)
Same as:
const app =
Acknowledgements
This project was kindly sponsored by nearForm.
License
Copyright Matteo Collina 2016, Licensed under MIT.