autoload-proxy

0.1.1 • Public • Published

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 load modules.js from dir where dir also contains a directory called modules.
  • 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).

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i autoload-proxy

      Weekly Downloads

      0

      Version

      0.1.1

      License

      none

      Last publish

      Collaborators

      • rthrfrd