Is it possible to specify a target directory when running npm install <package>
?
npm install (in a package directory, no arguments): Install the dependencies to the local node_modules folder. In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.
node. js - npm global install does not add packages to PATH on Windows 8.1 - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
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.)
As of npm version 3.8.6, you can use
npm install --prefix ./install/here <package>
to install in the specified directory. NPM automatically creates node_modules
folder even when a node_modules
directory already exists in the higher up hierarchy. You can also have a package.json
in the current directory and then install it in the specified directory using --prefix
option:
npm install --prefix ./install/here
As of npm 6.0.0, you can use
npm install --prefix ./install/here ./
to install the package.json in current directory to "./install/here" directory. There is one thing that I have noticed on Mac that it creates a symlink to parent folder inside the node_modules directory. But, it still works.
NOTE: NPM honours the path that you've specified through the --prefix
option. It resolves as per npm documentation on folders, only when npm install
is used without the --prefix
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With