Loades modules in an alternative to node.js native 'require' method, allowing to load a module with additional global-like variables (like __dirname or __filename).
Also useful, if you want to hide some global methods or variabels from your module scope.
npm install demander
Then make reference inside yor module...
const demand = require('demander');
const result = demand('filename');
Loads the module with desired behavior
path
- (string) A full path to the modulecontext
- (any) optional; Any context, that will be eccesable ander "this"arguments
- (object) optional; An object with arguments names as its properties names and arguments values as its properties values. For example:
{
paramA: 'value A',
paramB: 'value B'
}
options
- (object) optional; An object with optionsoptions.clearCache
- (boolen) optional;true
, if we want to delete saved module from the 'require' cache; by default it isfalse
options.hideGlobals
- (array) optional; A list of names of globals, that we want to hide in a loading module scope; by default it does't hide anything
Possible values:
// to hide defaults globals 'require', '__dirname' and '__filename'
options.hideGlobals = [];
// or
options.hideGlobals = ['all'];
// to hide only a spacific global variable
options.hideGlobals = ['require'];
// in this case it will not be possible to require another module from the loading module
any
- loaded module "exports" property
npm test