pje pje - 1 year ago 342
Node.js Question

npm local install package to custom location

Is it possible to specify a custom package destination for

npm install
, either through a command flag or environment variable?

By default, npm local installs end up in
within the current directory, but I want it to install into
within a different directory, for example
. How can I make that happen?

pje pje
Answer Source


You can do this by using the --prefix flag and the --global* flag.

[email protected]:~/foo $ npm install bower -g --prefix ./vendor/node_modules
[email protected] /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.


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).

You can run npm config list to see your current config and npm config edit to change it.


In general, npm's documentation is really helpful. The folders section is a good structural overview of npm and the config section answers this question.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download