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 directoriesmodules
andplugins
:
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 underplugins
will be installed first, thenmodules
.
If bothmodules
andplugins
have a module with the same name, the module inplugins
will be installed and the one inmodules
will 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 ofdb
underplugins
in 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