How to npm install to a specified directory?

coudy picture coudy · Jan 22, 2013 · Viewed 257.5k times · Source

Is it possible to specify a target directory when running npm install <package>?

Answer

coudy picture coudy · Jan 22, 2013

You can use the --prefix option:

mkdir -p ./install/here/node_modules
npm install --prefix ./install/here <package>

The package(s) will then be installed in ./install/here/node_modules. The mkdir is needed since npm might otherwise choose an already existing node_modules directory higher up in the hierarchy. (See npm documentation on folders.)