Reputation: 17783
I have a gulp
based build system. Currently I have some tasks, e.g. a task that is accessing npm
(require('npm')
) programmatically. In order to achieve it I need to specify npm
in my package.json
dependencies, so that require
can find it inside node_modules
. However npm
is obviously available along with node
& I also have npm
installed globally (latest 3.x version of npm
).
Is there a way to require a global instance of npm
? I do the same stuff e.g. with other npm packages (I mean I have global package installed but I duplicate it in package.json
to make it available via require
).
Upvotes: 1
Views: 118
Reputation: 2023
Yes you can do it by adding NODE_PATH to your environment variable eg:
export NODE_PATH=/usr/local/lib/node_modules/
After doing this you node should be able to find globally installed packages as well.
NOTE:your node module path may defer.
to make it permanent you can add the commmand to your ~/.bashrc
file
Upvotes: 2