Locally installed versus globally installed NPM modules

Rigil picture Rigil · Dec 9, 2014 · Viewed 28.8k times · Source

In my package.json file, I have bower listed as a dependency. After I run npm install, bower gets installed locally. When I try to run bower after installing it locally I get an error

"bower" is not recognized as an internal or external command

It seems the only way to resolve this is to install bower globally. Why should I have to do this? If my project contains a local copy of bower, why won't node use it?

Answer

Jimi picture Jimi · Dec 9, 2014

Installing locally makes bower available to the current project (where it stores all of the node modules in node_modules). This is usually only good for using a module like so var module = require('module'); It will not be available as a command that the shell can resolve until you install it globally npm install -g module where npm will install it in a place where your path variable will resolve this command.

Edit: This documentation explains it pretty thorougly.