Installing From Different Paths

Module Installer allows you to install modules from several different locations in sequence. Below is an example demonstrating installation of module from two directoriesmodulesandplugins:

installer.install([__dirname + '/modules', __dirname + '/plugins']);

The modules residing under these directories will be installed sequently in a REVERTED ORDER of parameters given to the functioninstall. It means that all modules underpluginswill be installed first, thenmodules.

If bothmodulesandpluginshave a module with the same name, the module inpluginswill be installed and the one inmoduleswill be skipped. For example:

Imagine you have a project structure that looks like following:

your-app
|- index.js
|- modules
|  |- users
|  |  |- meta.js
|  |  |- index.js
|  |- db
|  |  |- meta.js
|  |  |- index.js
|- plugins
|  |- db
|  |  |- meta.js
|  |  |- index.js

In yourindex.js, install modules and plugins respectively:

installer.install([__dirname + '/modules', __dirname + '/plugins']);

Then a call to$('db')will return instance ofdbunderpluginsin result. This mechanism is helpful should you want to keep your core application modules code intact (themodules), while still allow flexible replacement of some particular modules with ease.

Last updated