Monday, 15 September 2014

node.js - npm local install package to custom location -



node.js - npm local install package to custom location -

is possible specify custom bundle destination npm install, either through command flag or environment variable?

by default, npm local installs end in node_modules within current directory, want install node_modules within different directory, illustration vendor/node_modules. how can create happen?

tl;dr

you can using --prefix flag , --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 "global" installation, installed bins won't accessible through command line unless ~/foo/vendor/node_modules exists in path.

tl;r

every configurable attribute of npm can set in of 6 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 ./node_modules. global ones go prefix config variable (/usr/local default).

you can run npm config list see current config , npm config edit alter it.

ps

in general, npm's documentation helpful. folders section structural overview of npm , config section answers question.

node.js npm

No comments:

Post a Comment