Reputation: 76
Same title.
I don't want install every time with any project.
Just install once.
Thanks in advance.
Edit: I know install global but how to require it is my question.
Upvotes: 5
Views: 623
Reputation: 2810
After you install them global, use npm link
in project folder with package names(see npm link), to link them to that project. e.g. if your project requires lodash
use npm link lodash
.
Another way, if you want to have multiple little scripts(e.g. not projects) you can set the NODE_PATH
variable with path to where your npm stores global packages. And after that require('<global-module>')
will work without link and installing node_modules into folder.
Upvotes: 0
Reputation: 4103
Check Addenda: Package Manager Tips
Define NODE_PATH
with path local modules, example:
/usr/lib/node_modules
C:\Users\<Username>\AppData\Local\Yarn\Data\global\node_modules
And now you can call it.
Since the module lookups using node_modules
folders are all relative, and based on the real path of the files making the calls to require()
, the packages themselves can be anywhere.
Upvotes: 1
Reputation: 2476
Yes. possible. Install all the modules globally.
ie; npm install -g <module_name>
Then use it in your application as necessary.
But, this method is not advised.
Upvotes: 0