Add any path to node's require path
Simple straightforward tool to allow you to require locally
Install the package via
$ npm install @nodeutils/reqhere --save
Wherever you want to be a module root:
And everything from there down will be included.
project │ yourApp.js │ └───myModules │ index.js │ itemA.js │ ├───directoryA │ │ itemA.js │ │ itemB.js │ │ ... │ └───directoryB │ index.js
If myModules/index.js is given:
Then everything in that directory is added to the path, and the following will work from ANYWHERE in the application:
require("itemA"); //myModules/itemA.js require("directoryA/itemA"); //myModules/directoryA/itemA.js require("directoryA/itemB"); //myModules/directoryA/itemB.js require("directoryB"); //myModules/directoryV/index.js
What if I want to add multiple paths?
Not an issue. Add
require("@nodeutils/reqhere")(); as many times as you like, and it will append (both Unix and Windows tested).
Can I namespace?
You sure can, and it's a good idea too, so you can spot the difference between an installable module and a local one.
Make yourself a folder called something like
In there make a file called index.js containing
"use strict"; require("@nodeutils/reqhere")();
Add a folder inside
componentscalled, for example,
appput all your modules and files.
Done! From anywhere you can now `require("app/someModuleYouMade");
Need more help, found a bug? Raise an issue