autoload-proxy
v0.1.1
Published
Elegant module autoloading for node.
Downloads
1
Readme
autoload-proxy
Elegant module autoloading for node.
npm install autoload-proxy --save
// Requires harmony proxies to be enabled when running.
node --harmony_proxies main.js
Features
- Concise - Use JS syntax to traverse your code.
- Lazy - Does not explore file system to locate modules.
- No magic - 42 simple LOC.
Usage
require('autoload-proxy');
// Load core module
var server = π.http.createServer();
// Load npm module
var app = π.express();
// Load user module at ./dir/pkg/module
var thing = π.dir.pkg.module.makeThing();
// 'Use' references at any depth
var pkg = π.dir.pkg;
var otherThing = pkg.module.makeOtherThing();
// Always relative to the main script
var version = π['../package.json'].version;
// Camel-case converted to hyphens
var client = π.nodeRedis.createClient();
// Use p instead of π
var module = p.dir.module;
Caveats
- Cannot access a module if the directory it is in also contains a directory with the same name: Use
π.dir['modules.js']
to loadmodules.js
fromdir
wheredir
also contains a directory calledmodules
. - Accessing the contents of directories which are modules (i.e. containing an index.js) requires that the module directory name be prefixed with
_
(e.g.π.dir._module.component
).