Locally installed versus globally installed NPM modules Locally installed versus globally installed NPM modules node.js node.js

Locally installed versus globally installed NPM modules


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.


You can execute your local instance by typing the line below in cmd:

node_modules/bower/bin/bower <bower args>


We use both PHP and JavaScript, so we have composer and npm.

Each of the projects we work on have different packages both for runtime of the package as well as build/dev tools.

As there are version constraints in each project, installing version x of a package globally (that would be run from the command line), would cause us issues, we install all the tooling in each package. Much easier to define in the appropriate composer.json / package.json files.

But running the CLI tools is a pain if you have to constantly add an additional path to the command.

To that end, we have recommend to the team that the following paths are added to your $PATH in the appropriate .bashrc (or equivalent):

./vendor/bin:./node_modules/.bin

(EDIT: For Windows, the paths would be .\vendor\bin;.\node_modules\.bin;)

So, whilst in project X, we have access to the CLI tools for that project. Switch to project Y, and we get that projects tools.

Sure, you are going to get duplications, but each project is maintained by different teams (and some people are in multiple teams), so again, having 1 version in the global setup is an issue there.