1 | # Bijous
|
2 |
|
3 |
|
4 | [![Build Status](https://travis-ci.org/mbrio/bijous.svg?branch=master)](https://travis-ci.org/mbrio/bijous) [![Dependency Status](https://gemnasium.com/mbrio/bijous.svg)](https://gemnasium.com/mbrio/bijous) [![Code Climate](https://codeclimate.com/github/mbrio/bijous/coverage.png)](https://codeclimate.com/github/mbrio/bijous)
|
5 |
|
6 | [![NPM Status](https://nodei.co/npm/bijous.png?downloads=true)](https://npmjs.org/package/bijous)
|
7 |
|
8 | An asynchronous module loader for node.js.
|
9 |
|
10 | ## Installation
|
11 |
|
12 | You can use this node module in your project by executing the following:
|
13 |
|
14 | ```Shell
|
15 | npm install bijous
|
16 | ```
|
17 |
|
18 | or by saving it to your *package.json* file:
|
19 |
|
20 | ```Shell
|
21 | npm install --save bijous
|
22 | ```
|
23 |
|
24 | ## Testing
|
25 |
|
26 | ```Shell
|
27 | npm install && npm test
|
28 | ```
|
29 |
|
30 | ## Modules
|
31 |
|
32 | All modules must conform to the rules set forth by [node](http://nodejs.org/api/modules.html) with the caveat that the module **MUST** export a method that receives a `context` argument and `done` argument. The `context` is a reference to the `Bijous` instance loading the module; and `done` is the callback used when the module has completed loading. The first argument to `done` is an error object and should only be supplied when an error has occurred; the second argument is an object that can be later references by the `Bijous` instance property `modules` which collects the results for each of the modules loaded. The `modules` property references the module loaded by it's filename, if we take the following code as an example and assume the code resides in a file called *modules/server/index.js*:
|
33 |
|
34 | ```JavaScript
|
35 | var express = require('express');
|
36 |
|
37 | exports = module.exports = function (context, done) {
|
38 | var app = express();
|
39 |
|
40 | done(null, {
|
41 | app: app,
|
42 | express: express
|
43 | });
|
44 | };
|
45 | ```
|
46 |
|
47 | Then the results from the server module could be accessed via:
|
48 |
|
49 | ```JavaScript
|
50 | var app = bijous.modules.server.app;
|
51 | app.use(middleware());
|
52 | ```
|
53 |
|
54 | ## Usage
|
55 |
|
56 | The following code will load all modules within the `modules` folder.
|
57 |
|
58 | ```JavaScript
|
59 | var Bijous = require('bijous');
|
60 | var bijous = new Bijous();
|
61 | bijous.require();
|
62 | ```
|
63 |
|
64 | ## License
|
65 |
|
66 | ICS © 2014 Michael Diolosa <<michael.diolosa@gmail.com>>
|