module-index

Includes all modules within it's directory as an export.

npm install module-index
8 downloads in the last month

module-index

The module-index module will include all it's sibling modules and return them as an export.

Installation

$ npm install module-index

Example

Say you have a directory structure like so:

- app/
  - controllers/
    - welcome.js
    - blog.js
    - contact.js
  - index.js

Then the you can access all the controllers by adding a controllers/index.js file like so:

// app/controllers/index.js
require('module-index')(module);
// app/index.js
var controllers = require('./controllers'),
    app         = require('apparator')();

app.get('/welcome', controllers.welcome.index);
app.get('/blogs', controllers.blog.list);
// ...

Infact... you can entirley skip out making a new file:

// app/index.js
var controllers = require('module-index')('./controller');
npm loves you