0.2.0 • Published 11 years ago
auto-loader v0.2.0
node-auto-loader
A simple auto loader for nodejs
Install
$ sudo npm install auto-loaderUsage
suppose you had a directory structure like this
app/
└── controllers
├── Application.js
└── User.jsyou could build a tree with auto-loader like this
var app = require('auto-loader').load(__dirname +'/app')if you were to console.log the contents of that object you would see this
{ _path: '/Users/jwerle/repos/node-auto-loader/test/app',
controllers:
{ _path: '/Users/jwerle/repos/node-auto-loader/test/app/controllers',
Application: [Getter/Setter],
User: [Getter/Setter] } }all modules are wrapped in a getter and make a call to require to fetch their definitions and are cached after the first require
app.controllers.Application; // [Function: Application]api
.load(dir)
dirdirectory to load recursively
example
var loader = require('auto-loader')
var modules = loader.load(__dirname);
console.log(modules);
/**
{ _path: '/Users/jwerle/repos/node-auto-loader/test/module',
module1: [Getter/Setter],
module2: [Getter/Setter],
module3: [Getter/Setter] }
**/Loader(dir)
creates a new Loader instance
dir- root director for loader
example
var loader = new Loader(__dirname)
// load the currenty directory
loader.load();license
MIT
