Skip to content
jarnoux edited this page Dec 1, 2013 · 2 revisions

Rig is the constructor for your app. It is the entry-point to specifying how your app is structured and what resource should be configured with what and how to route it.

Example

// server.js
var Rig  = require('rig'),
    rig  = new Rig({
        config: 'config.json',
        routes: 'routes.json'
    });

rig.register('controllers/');
rig.register('middleware/');
rig.register('models/');

rig.route();

rig.listen(3000);
console.log('app listening on port', 3000);

Faster example

// server.js
var Rig  = require('rig'),
    rig  = new Rig({
        config: 'config.json',
        routes: 'routes.json',
        resources: ['controllers/', 'middleware/', 'models/']
    });

rig.listen(3000);
console.log('app listening on port', 3000);

That's right: if you only need the 1-argument version of the rig.register function (which should be often), then you can specify those arguments in an array in the resources parameter and Rig will register and route everything automatically for you (See below for more about that).

API

Rig({ config, routes, [resources] })

The constructor for a new Rig app.

  • String config: The path of the config file absolute or relative to the root of the app.
  • String routes: The path of the routes file absolute or relative to the root of the app.
  • String[] resources (optional): The resources path to be sequentially given to rig.register. If this argument is present, rig will register those resources and call Rig.route

Rig.register

See the registry.

Rig.route()

Applies the routing configurations to the app to define what resources is called when. You can read more about routing on the Express.js website.

Rig.listen(port, [hostname], [backlog], [callback])

See Express.listen which is in turn Node's listen

Rig.engine

See Express.engine.

Clone this wiki locally