Type of node installation
In npm 1.0, there are two ways to install things:
1. globally —- This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin, where {prefix} is usually something like /usr/local. It also installs man pages in{prefix}/share/man, if they’re supplied.
npm install packagename
2. locally —- This installs your package in the current working directory. Node modules go in ./node_modules, executables go in./node_modules/.bin/, and man pages aren’t installed at all.
npm install
packagename
WHICH TO CHOOSE
Whether to install a package globally or locally depends on the global config, which is aliased to the -g command line switch.
Just like how global variables are kind of gross, but also necessary in some cases, global packages are important, but best avoided if not needed.
In general, the rule of thumb is:
1. If you’re installing something that you want to use in your program, using require(‘whatever’), then install it locally, at the root of your project.
2. If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
Source: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation