Where does npm install packages?

后端 未结 23 1328
梦毁少年i
梦毁少年i 2020-11-22 06:03

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

相关标签:
23条回答
  • 2020-11-22 06:22

    If you have Visual Studio installed, you will find it comes with its own copy of node separate from the one that is on the path when you installed node yourself - Mine is in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\NodeJs.

    If you run the npm command from inside this directory you will find out which node modules are installed inside visual studio.

    0 讨论(0)
  • 2020-11-22 06:23

    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.

    0 讨论(0)
  • 2020-11-22 06:23

    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.

    0 讨论(0)
  • 2020-11-22 06:24

    To get a compact list without dependencies simply use

    npm list -g --depth 0
    
    0 讨论(0)
  • 2020-11-22 06:25

    The easiest way would be to do

    npm list -g

    to list the package and view their installed location.

    I had installed npm via chololatey, so the location is

    C:\MyProgramData\chocolatey\lib\nodejs.commandline.0.10.31\tools\node_modules

    C:\MyProgramData\ is chocolatey repo location.

    0 讨论(0)
  • 2020-11-22 06:26

    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.
    0 讨论(0)
提交回复
热议问题