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.jsrequire("directoryA/itemA"); //myModules/directoryA/itemA.jsrequire("directoryA/itemB"); //myModules/directoryA/itemB.jsrequire("directoryB"); //myModules/directoryV/index.js
Not an issue. Add
require("@nodeutils/reqhere")(); as many times as you like, and it will append (both Unix and Windows tested).
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
components called, for example,
app put all your modules and files.
Done! From anywhere you can now `require("app/someModuleYouMade");
Need more help, found a bug? Raise an issue