1.0.1 • Published 9 years ago

series-boot-phase v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

Series Boot Phase

NPM version Build Status Coverage Status Dependencies

Series boot phase when booting an application.

Installation

$ npm install series-boot-phase

Usage

var series = require( 'series-boot-phase' );

series( ...fcns )

Creates a series boot phase based on provided input functions.

function beep( app, next ) {
	// Do something...
	next();
}
function boop( app, next ) {
	// Do something else...
	process.nextTick( next );
}

var phase = series( beep, boop );

A function array is also accepted.

var phase = series( [ beep, boop ] );

Notes

  • The phase is considered complete when all functions have successfully returned.
  • If a `function` errors or provides an `error` argument to the `next` callback, the phase aborts and causes the [boot](https://github.com/kgryte/node-app-boot) sequence to fail.

Examples

var express = require( 'express' ),
	bootable = require( 'app-boot' ),
	series = require( 'series-boot-phase' );

var phase, boot, app;

// Mock connecting to a database...
function db1( app, config, locals, next ) {
	console.log( 'Connecting to database 1...' );
	setTimeout( onTimeout, 1000 );
	function onTimeout() {
		console.log( 'Connected to database 1...' );
		locals.db1 = {
			'beep': 'boop'
		};
		next();
	}
}

// Mock connecting to a different database...
function db2( app, config, locals, next ) {
	console.log( 'Connecting to database 2...' );
	setTimeout( onTimeout, 500 );
	function onTimeout() {
		console.log( 'Connected to database 2...' );
		locals.db2 = {
			'bop': 'bip'
		};
		next();
	}
}

// Callback invoked once an application boots...
function done( error ) {
	if ( error ) {
		throw error;
	}
	console.log( 'Application booted...' );
}

// Create a new application:
app = express();

// Create a boot phase:
phase = series( db1, db2 );

// Create a boot function:
boot = bootable( app, {}, {} );

// Register the phase:
boot.phase( phase );

// Boot the application:
boot( done );

To run the example code from the top-level application directory,

$ DEBUG=* node ./examples/index.js

See Also

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

MIT license.

Copyright

Copyright © 2015. Athan Reines.