Plugin.js
Features
- ability to load entire directories
- add remote plugins (dnode)
Example
bootstrap.js
var plugin = express = ;
config.js
exports { server;}
someRoutes.js
module { server}
Plugin API
loader .plugin(plugInto, ...)
Initializes the loader for local / remote plugins. plugInto
is passed into the first parameter when calling .plugin()
on each required module.
loader.use(extension)
Extends the loader. This allows you to customize how modules are loaded into your sandbox.
;
loader.params(keyOrParams, value)
Get / set params
bootstrap.js
;
server.js
exports { console;}
loader.require(source, ...)
path to the plugins
loader;
loader.load(callback)
loads the required dependencies
loader.module(search)
Returns one loaded module based on the search query. Note that calling this method may load the given module if it hasn't already. Here's a real-world example:
bootstrap.js
;
server.js
exportsisHttpServer = true; //not needed - just used for searchingexports { var server = ; server; return server;}
routes.js
exports { var server = loader; server}
Also note that you can search based on attributes. Here's routes.js
again:
exports { var server = loader; //do stuff here}
loader.modules(search)
Just like loader.module(search)
, but returns multiple modules.
loader.exports
This is all the plugins combined, and it's set once everything's loaded.