Require-up
Require modules from anywhere up the parent directories. Like find-up but for require
.
Optionally, a new syntax ('.../'
) which will work with regular require/import calls.
Install
$ npm install --save require-up
Usage
If you have a structure like this:
proj
├───index.js
├───utils.js
└───foo
└───bar
└───some-file.js
// proj/foo/bar/some-file.jsconst requireUp = const utils =
It will look for (in this order):
proj/foo/bar/node_modules/utils
proj/foo/bar/utils
proj/foo/node_modules/utils
proj/foo/utils
proj/node_modules/utils
proj/utils # << found
Register
A new syntax ('.../'
) which will work with regular require/import calls.
// proj/index.js
// proj/foo/bar/some-file.js
CAUTION
BEWARE: Registering new syntax patches core module.js's Module._resolveFilename
.