0.1.1 • Published 11 years ago
autoload-proxy v0.1.1
autoload-proxy
Elegant module autoloading for node.
npm install autoload-proxy --save
// Requires harmony proxies to be enabled when running.
node --harmony_proxies main.jsFeatures
- 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.jsfromdirwherediralso 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).