This module extends the default Node.js require with capabilities to require nested modules, independent of where they are nested.
npm install require-it --save
myPackage
+ node_modules
| + direct-dependecy
| | + node_modules
| | | \ nested-module
| | | + index.js
| | | \ package.json
| | + index.js
| | \ package.json
| + index.js
| \ package.json
+ index.js
\ package.json
myPackage/index.js
:
const { requireIt } = require('require-it');
// it will work and won't throw error
const nestedModule = requireIt('nested-module');
Requires the given local module, independent of which level it is.
Returns the local path, which could be required by require
.
Returns the local path, which could be required by require
without the main JS file, i.e., the path to the module's directory.
Requires the given global module.
Returns the global path, which could be required by require
.
Returns the global path, which could be required by require
without the main JS file, i.e., the path to the module's directory.
Requires the given module found in the given root directory.
Returns the module's path, which could be required by require
, found in the given root directory.
Returns the module's path, which could be required by require
without the main JS file, i.e., the path to the module's directory, found in the given root directory.