Where does npm install packages?

2019-01-01 04:23发布

Can someone tell me where can I find the Node.js modules, which I installed using npm?

17条回答
只靠听说
2楼-- · 2019-01-01 05:01

As the other answers say, the best way is to do

npm list -g

However, if you have a large number of npm packages installed, the output of this command could be very long and a big pain to scroll up (sometimes it's not even possible to scroll that far back).

In this case, pipe the out to the more program, like this

npm list -g | more
查看更多
只靠听说
3楼-- · 2019-01-01 05:03

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.

See the documentation.

查看更多
君临天下
4楼-- · 2019-01-01 05:04

Use the npm root -g command for find out your global npm path.

Example:

$ npm root -g
/usr/local/lib/node_modules
查看更多
怪性笑人.
5楼-- · 2019-01-01 05:10

From the docs:

In npm 1.0, there are two ways to install things:

  • globally —- This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin, where {prefix} is usually something like /usr/local. It also installs man pages in {prefix}/share/man, if they’re supplied.

  • locally —- This installs your package in the current working directory. Node modules go in ./node_modules, executables go in ./node_modules/.bin/, and man pages aren’t installed at all.

You can get your {prefix} with npm config get prefix. (Useful when you installed node with nvm).

查看更多
何处买醉
6楼-- · 2019-01-01 05:14

Windows 10: When I ran npm prefix -g, I noticed that the install location was inside of the git shell's path that I used to install. Even when that location was added to the path, the command from the globally installed package would not be recognized. Fixed by:

  1. running npm config edit
  2. changing the prefix to 'C:\Users\username\AppData\Roaming\npm'
  3. adding that path to the system path variable
  4. reinstalling the package with -g.
查看更多
登录 后发表回答