Reputation: 100350
I install this module called zmq with npm install -g zmq
Say I am in a new directory and I create a simple node.js file:
//test.js
var zmq = require('zmq');
console.log(zmq);
...if I run this, it will not be able to find the zmq
package, even though I installed it globally. In order for the script to work, I have to run npm install zmq
without the -g flag, which creates a node_modules folder in the same directory. I don't want that node_modules folder there.
I am failing to see the purpose of the -g flag, since none of my node programs seem to run without a node_modules folder.
I am on a Mac, but I have had the same problem on Windows and Linux.
What am I missing?
Upvotes: 1
Views: 64
Reputation: 1785
From npm's website:
- Local install (default): puts stuff in ./node_modules of the current package root.
- Global install (with -g): puts stuff in /usr/local or wherever node is installed.
- Install it locally if you're going to require() it.
- Install it globally if you're going to run it on the command line.
It's built this way so that each project can maintain separate dependencies and you don't have any issues trying to figure out which version goes with which project at a global level.
I'm not sure there's a way to do what you want it to do, and I don't think it would be recommended, even if there was.
Hope this helps!
Upvotes: 2