Boot
Boot an application.
Installation
$ npm install app-boot
Usage
var bootable = ;
bootable( [...args] )
Returns a boot function
. All provided arguments
are passed to each registered phase.
var app = ;var boot = ;
boot.phase( fcn[, thisArg] )
Registers a new boot phase. On boot, phases sequentially execute according to registration order.
{// ...do something...;}{var err;// ...do something...if errreturn ;;}boot;
Each phase receives all boot arguments
plus an additional callback to invoke after a phase is complete.
var logger =config = ;{logger;;}boot = ;boot;
To specify the this
context for a phase, provide a thisArg
.
var ctx ='beep': 'boop';{console;// returns 'boop';}boot = ;boot;
To mimic async-waterfall, provide a locals object
upon creating a boot
sequence.
{localsbeep = 'boop';;}{console;// returns 'boop';}boot = ;boot;
boot( clbk )
Boots an application and invokes a callback once all phases complete.
;{if errorthrow error;console;}
Calling any phase's next
callback with an error
argument will cause the boot sequence to abort.
{// ...do something...;}{// ...never reached...;}{if errorconsole;// returns 'phase1 error'}boot = ;boot;;
See Also
- parallel-boot-phase
- Creates a parallel boot phase when booting an application. Useful for when phase functions are independent; e.g., connecting to two mutually exclusive databases.
- series-boot-phase
- Creates a series boot phase containing subphases when booting an application. Useful for phase abstraction; e.g., creating a higher-level middleware phase from several subphases (initial tasks, routes, error handling, etc).
- bootable
- Whereas
bootable
binds an application to the phasethis
context, this module allows passing the application and any other parameters as arguments to each phase. - Rather than hang methods off (and thus mutate) the application, this module returns a
function
which wraps the application in a closure.
- Whereas
- express
- This module employs a design pattern similar to Express' middleware pattern, but with a more general interface.
Examples
var express =debug = 'app-boot:example'bootable = ;var boot app;// Bind middleware to the application...{;app;;{console;;}}// Mock connecting to a db...{;process;{appdb = {};;}}// Mock creating a server and listening on a port...{;process;{appserver = {};;}}// Callback invoked after completing a boot sequence...{if errorthrow error;;}// Create an application:app = ;// Create a boot function:boot = ;// Register phases:boot;// Boot the application:;
To run the example code from the top-level application directory,
$ DEBUG=* node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Athan Reines.