Where does npm install packages?

后端 未结 23 1330
梦毁少年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:26

    From the docs:

    Packages are dropped into the node_modules folder under the prefix. When installing locally, this means that you can require("packagename") to load its main module, or require("packagename/lib/path/to/sub/module") to load other modules.

    Global installs on Unix systems go to {prefix}/lib/node_modules. Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)

    Scoped packages are installed the same way, except they are grouped together in a sub-folder of the relevant node_modules folder with the name of that scope prefix by the @ symbol, e.g. npm install @myorg/package would place the package in {prefix}/node_modules/@myorg/package. See scope for more details.

    If you wish to require() a package, then install it locally.

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

    Read about locally.
    Read about globally.

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

    In Ubuntu 14.04 they are installed at

    /usr/lib/node_modules

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

    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 output to the more program, like this

    npm list -g | more
    
    0 讨论(0)
  • 2020-11-22 06:29

    If a module was installed with the global (-g) flag, you can get the parent location by running:

    npm get prefix
    

    or

    npm ls -g --depth=0
    

    which will print the location along with the list of installed modules.

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

    Btw, npm will look for node_modules in parent folders (up to very root) if can not find in local.

    0 讨论(0)
  • 2020-11-22 06:32
    • Echo the config: npm config ls or npm config list

    • Show all the config settings: npm config ls -l or npm config ls --json

    • Print the effective node_modules folder: npm root or npm root -g

    • Print the local prefix: npm prefix or npm prefix -g

      (This is the closest parent directory to contain a package.json file or node_modules directory)


    • npm-config | npm Documentation
    • npm-root | npm Documentation
    • npm-prefix | npm Documentation
    0 讨论(0)
提交回复
热议问题