Where does npm install packages?
The command npm root
will tell you the effective installation directory of your npm packages.
If your current working directory is a node package or a sub-directory of a node package, npm root
will tell you the local installation directory. npm root -g
will show the global installation root regardless of current working directory.
Example:
$ npm root -g
/usr/local/lib/node_modules
See the documentation.
On windows I used npm list -g
to find it out. By default my (global) packages were being installed to C:\Users\[Username]\AppData\Roaming\npm
.
For globally-installed modules:
The other answers give you platform-specific responses, but a generic one is this:
When you install global module with npm install -g something
, npm looks up a config variable prefix
to know where to install the module.
You can get that value by running npm config get prefix
To display all the global modules available in that folder use npm ls -g --depth 0
(depth 0
to not display their dependencies).
If you want to change the global modules path, use npm config edit
and put prefix = /my/npm/global/modules/prefix
in the file or use npm config set prefix /my/npm/global/modules/prefix
.
When you use some tools like nodist, they change the platform-default installation path of global npm modules.
Global libraries
You can run npm list -g
to see which global libraries are installed and where they're located. Use npm list -g | head -1
for truncated output showing just the path. If you want to display only main packages not its sub-packages which installs along with it - you can use - npm list --depth=0
which will show all packages and for getting only globally installed packages, just add -g i.e. npm list -g --depth=0
.
On Unix systems they are normally placed in /usr/local/lib/node
or /usr/local/lib/node_modules
when installed globally. If you set the NODE_PATH
environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\AppData\npm\node_modules
Windows 7, 8 and 10 - %USERPROFILE%\AppData\Roaming\npm\node_modules
Non-global libraries
Non-global libraries are installed the node_modules
sub folder in the folder you are currently in.
You can run npm list
to see the installed non-global libraries for your current location.
When installing use -g option to install globally
npm install -g pm2
- pm2 will be installed globally. It will then typically be found in /usr/local/lib/node_modules
(Use npm root -g
to check where.)
npm install pm2
- pm2 will be installed locally. It will then typically be found in the local directory in /node_modules