> npm install --prefix <custom directory path>
Example:
> npm install --prefix C:\MyInstallations
With this,
node_modules will be created in C:\MyInstallations folder.
For reference, nice content from stack overflow.
TL;DR
You can do this by using the --prefix flag and the --global* flag.
pje@friendbear:~/foo $ npm install bower -g --prefix ./vendor/node_modules
bower@0.7.0 /Users/pje/foo/vendor/node_modules/bower
*Even though this is a "global" installation, installed bins won't be accessible through the command line unless ~/foo/vendor/node_modules exists in PATH.
TL;R
Every configurable attribute of npm can be set in any of six different places. In order of priority:
- Command-Line Flags:
--prefix ./vendor/node_modules
- Environment Variables:
NPM_CONFIG_PREFIX=./vendor/node_modules
- User Config File:
$HOME/.npmrc or userconfig param
- Global Config File:
$PREFIX/etc/npmrc or userconfig param
- Built-In Config File:
path/to/npm/itself/npmrc
- Default Config: node_modules/npmconf/config-defs.js
By default, locally-installed packages go into ./node_modules. global ones go into the prefix config variable (/usr/local by default).