Skip to content
This module extends the default nodejs require with capabilities to require nested modules, independent on where they are nested.
TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
package.json
tsconfig.json
tslint.json
yarn.lock

README.md

require-it

Build Status dependency Status devDependency Status

This module extends the default nodejs require with capabilities to require nested modules, independent on where they are nested.

Install

npm install require-it --save

Example

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');

API

requireIt(moduleName)

Requires the given local module, indenpendent on which level is it.

requireIt.resolve(moduleName)

Returns the local path which could be required by require.

requireIt.directory(moduleName)

Returns the local path wich could be required by require without the main JS file, ie. the path to the module's directory.

requireGlobal(globalModuleName)

Requires the given global module.

requireGlobal.resolve(globalModuleName)

Returns the global path which could be required by require.

requireGlobal.directory(globalModuleName)

Returns the global path wich could be required by require without the main JS file, ie. the path to the module's directory.

requireFrom(moduleName, root)

Requires the given module, found in the given root directory.

requireFrom.resolve(moduleName, root)

Returns the module's path which could be required by require, found in the given root directory.

requireFrom.directory(moduleName, root)

Returns the module's path wich could be required by require without the main JS file, ie. the path to the module's directory, found in the given root directory.

You can’t perform that action at this time.