0.1.0 • Published 11 years ago
automod v0.1.0
Automod
Module loading and name-spacing for Node.js app.s
Installation
npm install --save-dev automod
What
Autmod helps you expose and use modules within your app. With node's exports system, it effectively becomes a dependecy injection module.
Why
One day I got sick of writing the same require statements everywhere.
How
In your server's entry file:
var mods = require('automod');
mods({ignore: [], data: {}, path: ''});Ignore Automod will examine all directories startiing on the same directory as your entry file and try and
requirethem.Data This is to pass other
requiredmodules to your modules. Consider:var mods = require('automod'); var mongo = require('mongodb'); var persistence = { Db: mongo.Db, Server: mongo.Server, Connection: mongo.Connection }; mods({ignore: [], data: persistence, path: ''});Now the persistence data will be available in you module.
In your modules:
A sample users module
module.exports = function(app) { var Users = app.data.persistence.Db.collection('users'); };
0.1.0
11 years ago