csdnceshi63
elliott.david
2011-05-08 09:39
采纳率: 25%
浏览 493

Npm 在哪里安装软件包?

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

转载于:https://stackoverflow.com/questions/5926672/where-does-npm-install-packages

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

17条回答 默认 最新

  • csdnceshi54
    hurriedly% 2011-05-08 09:47
    已采纳

    Global libraries

    You can run npm list -g to see where global libraries are installed.

    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.

    点赞 评论
  • csdnceshi72
    谁还没个明天 2011-05-08 16:30

    In earlier versions of NPM modules were always placed in /usr/local/lib/node or wherever you specified the npm root within the .npmrc file. However, in NPM 1.0+ modules are installed in two places. You can have modules installed local to your application in /.node_modules or you can have them installed globally which will use the above.

    More information can be found at https://github.com/isaacs/npm/blob/master/doc/install.md

    点赞 评论
  • csdnceshi66

    On windows I used npm list -g to find out by default my (global) packages were being installed to C:\Users\[Username]\AppData\Roaming\npm.

    点赞 评论
  • csdnceshi57
    perhaps? 2014-06-18 21:31

    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.

    点赞 评论
  • csdnceshi67
    bug^君 2014-09-11 05:28

    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.

    点赞 评论
  • csdnceshi77
    狐狸.fox 2014-12-04 15:50

    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.

    When you use some tools like nodist, they change the platform-default installation path of global npm modules.

    点赞 评论
  • csdnceshi58
    Didn"t forge 2016-05-11 22:48

    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
    
    点赞 评论
  • weixin_41568183
    零零乙 2016-05-12 10:32

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

    Example:

    $ npm root -g
    /usr/local/lib/node_modules
    
    点赞 评论
  • csdnceshi76
    斗士狗 2016-07-03 20:16

    In Ubuntu 14.04 they are installed at

    /usr/lib/node_modules

    点赞 评论
  • csdnceshi79
    python小菜 2016-08-02 13:35

    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).

    点赞 评论
  • csdnceshi64
    游.程 2016-08-24 14:19

    If module was installed with global (-g) flag, you can get parent location by running following command

    npm get prefix

    or

    npm ls -g --depth=0

    which will print location along with list of installed modules

    Cheers :-)

    点赞 评论
  • csdnceshi54
    hurriedly% 2016-08-25 09:54

    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.

    点赞 评论
  • csdnceshi76
    斗士狗 2017-05-20 09:45

    Not direct answer but may help ....

    The npm also has a cache folder, which can be found by running npm config get cache (%AppData%/npm-cache on Windows).

    The npm modules are first downloaded here and then copied to npm global folder (%AppData%/npm/Roaming on Windows) or project specific folder (your-project/node_modules).

    So if you want to track npm packages, and some how, the list of all downloaded npm packages (if the npm cache is not cleaned) have a look at this folder. The folder structure is as {cache}/{name}/{version}

    This may help also https://docs.npmjs.com/cli/cache

    点赞 评论
  • weixin_41568196
    撒拉嘿哟木头 2017-10-30 04:42

    You can find globally installed modules by the command

    npm list -g
    

    It will provide you the location where node.js modules have been installed.

    C:\Users\[Username]\AppData\Roaming\npm
    

    If you install node.js modules locally in a folder, you can type the following command to see the location.

    npm list
    
    点赞 评论
  • csdnceshi69
    YaoRaoLov 2018-01-02 21:43

    If you are looking for the executable that npm installed, maybe because you would like to put it in your PATH, you can simply do

    npm bin
    

    or

    npm bin -g
    
    点赞 评论
  • csdnceshi63
    elliott.david 2018-09-10 14:24

    If you're trying to access your global dir from code, you can backtrack from process.execPath. For example, to find wsproxy, which is in {NODE_GLOBAL_DIR}/bin/wsproxy, you can just:

    path.join(path.dirname(process.execPath), 'wsproxy')
    
    点赞 评论
  • csdnceshi78
    程序go 2018-10-17 21:22

    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.
    点赞 评论

相关推荐