node-packages is require.js for node.js.
Motification
- Flattens & simplifies application structure.
- Better encapsulation.
- More consistent.
Example
- package.json - application package
- lib/ - javascript source files
- index.js - main entry point
- packages/ - application components
- config/ - application config component
- http.server/ - http server component
- index.js - package entry point
- http.routes/ - http routes
- index.js
In lib/index.js
, you'll need something like:
var packages = ; packages;
In http.server/index.js
, you might have something like:
exportsrequire = "express" "config";exports { var app = app; return app;};
In http.routes/index.js
, you might have something like:
exportsrequire = "http.server";exports { app;};
Packages API
packages packages()
Initializes new packages loader
packages.add(name, package)
Adds a package. Below's an example where this might be useful.
lib/index.js
:
var packages = ; module { packages ;}
lib/packages/http.server/index.js
:
exportsrequire = "config";exports { //init server}
packages.require(path[, path])
loads packages from a directory
packages.load()
loads all the packages
packages.exports
all the loaded packages
Package API
exportsrequire = "package.name" "multiple.packages.*" /package.to.match/ ;exports { };