Where does npm install packages?

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

    I was beginning to going mad searching the real configuration, so here is the all list of configuration files on linux:

    • /etc/npmrc
    • /home/youruser/.npmrc
    • /root/.npmrc

    on windows: - c/Program\ Files/nodejs/node_modules/npm/npmrc

    Then in the file the prefix is configured:

    prefix=/usr
    

    The prefix is defaulted to /usr in linux, to ${APPDATA}\npm in windows

    The node modules are under $prefix tree, and the path should contain $prefix/bin

    There may be a problem :

    • When you install globally, you use "sudo su" then the /root/.npmrc may be used!
    • When you use locally without sudo: for your user its the /home/youruser/.npmrc.
    • When your path doesn't represent your prefix
    • When you use npm set -g prefix /usr it sets the /etc/npmrc global, but doesn't override the local

    Here is all the informations that were missing to find what is configured where. Hope I have been exhaustive.

提交回复
热议问题