node.js 如何列出 npm 用户安装的软件包?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17937960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:08:46  来源:igfitidea点击:

How to list npm user-installed packages?

node.jsnpmpackage-managers

提问by lolski

How do I list the user-installed package ONLY in npm? When I do npm -g listit outputs every package and their dependencies, which is not what I want.

如何仅在 中列出用户安装的软件包npm?当我这样做时,npm -g list它会输出每个包及其依赖项,这不是我想要的。

回答by aris

This works pretty well too: npm list -g --depth=0

这也很有效: npm list -g --depth=0

  • npm: the Node package manager command line tool
  • list -g: display a tree of every package found in the user's folders (without the -g option it only shows the current directory's packages)
  • depth 0 /?—?depth=0: avoid including every package's dependencies in the tree view
  • npm:Node 包管理器命令行工具
  • list -g:显示在用户文件夹中找到的每个包的树(没有 -g 选项,它只显示当前目录的包)
  • depth 0 /?—?depth=0: 避免在树视图中包含每个包的依赖项

回答by Gil

You can get a list of all globally installed modules using:

您可以使用以下方法获取所有全局安装模块的列表:

ls `npm root -g`

ls `npm root -g`

回答by arcseldon

As of 13 December 2015

截至 2015 年 12 月 13 日

npm list illustration

npm 列表插图

Whilst I found the accepted answer 100% correct, and useful, wished to expand upon it a little based on my own experiences, and hopefully for the benefit of others too. (Here I am using the terms package and module interchangeably)

虽然我发现接受的答案 100% 正确且有用,但希望根据我自己的经验对其进行一些扩展,并希望对其他人也有所帮助。(这里我交替使用术语包和模块)

In answer to the question, yes the accepted answer would be:

在回答这个问题时,是的,接受的答案是:

npm list -g --depth=0

You might wish to check for a particular module installed globally, on *nix systems / when grep available. This is particularly useful when checking what version of a module you are using (globally installed, just remove the -g flag if checking a local module):

您可能希望在 *nix 系统上/当 grep 可用时检查全局安装的特定模块。这在检查您使用的模块版本时特别有用(全局安装,如果检查本地模块,只需删除 -g 标志):

npm list -g --depth=0 | grep <module_name>

If you'd like to see all available (remote) versions for a particular module, then do:

如果您想查看特定模块的所有可用(远程)版本,请执行以下操作:

npm view <module_name> versions

Note, versionsis plural. This will give you the full listing of versions to choose from.

注意,versions是复数。这将为您提供可供选择的完整版本列表。

For latest remote version:

对于最新的远程版本:

npm view <module_name> version  

Note, versionis singular.

注意,版本是单数。

To find out which packages need to be updated, you can use

要找出哪些软件包需要更新,您可以使用

npm outdated -g --depth=0

To update global packages, you can use

要更新全局包,您可以使用

npm update -g <package>

To update all global packages, you can use:

要更新所有全局包,您可以使用:

npm update -g

(However, for npm versions less than 2.6.1, please also see this linkas there is a special script that is recommended for globally updating all packages).

(但是,对于低于 2.6.1 的 npm 版本,也请参阅此链接,因为有一个特殊的脚本推荐用于全局更新所有包)。

The above commands should work across NPM versions 1.3.x, 1.4.x, 2.x and 3.x

上述命令应该适用于 NPM 版本 1.3.x、1.4.x、2.x 和 3.x

回答by Alireza Fattahi

I prefer tools with some friendly gui!

我更喜欢带有一些友好 gui 的工具!

I used npm-guiwhich gives you list of local and global packages

我使用npm-gui它为您提供本地和全局包的列表

The package is at https://www.npmjs.com/package/npm-guiand https://github.com/q-nick/npm-gui

该软件包位于https://www.npmjs.com/package/npm-guihttps://github.com/q-nick/npm-gui

//Once
npm install -g npm-gui

cd c:\your-prject-folder
npm-gui localhost:9000

At your browser http:\\localhost:9000

在您的浏览器 http:\\localhost:9000

npm-gui

npm-gui

回答by Karthik damodara

For project dependencies use:

对于项目依赖项,请使用:

npm list --depth=0

For global dependencies use:

对于全局依赖项,请使用:

npm list -g --depth=0

回答by prosti

npm ls

npm listis just an alias for npm ls

npm list只是一个别名 npm ls

For the extended info use

对于扩展信息使用

npm la    
npm ll

You can always set --depth=0at the end to get the first level deep.

你总是可以--depth=0在最后设置以获得第一级深度。

npm ls --depth=0

You can check development and production packages.

您可以检查开发和生产包。

npm ls --only=dev
npm ls --only=prod

To show the info in jsonformat

json格式显示信息

npm ls --json=true

The default is false

默认是 false

npm ls --json=false

You can insist on long format to show extended information.

您可以坚持使用长格式来显示扩展信息。

npm ls --long=true

You can show parseable output instead of tree view.

您可以显示可解析的输出而不是树视图。

npm ls --parseable=true

You can list packages in the global install prefix instead of in the current project.

您可以在全局安装前缀中而不是在当前项目中列出包。

npm ls --global=true
npm ls -g // shorthand

Full documentation you can find here.

您可以在此处找到完整的文档。

回答by Piyush Sagar

Node has a concept of Local modules & Global modules

Node 有本地模块和全局模块的概念

Local modules are located within current project directory.

本地模块位于当前项目目录中。

Global Modulesare generally located at user's home directory, though we can change the path where global modules resides.

全局模块通常位于用户的主目录,但我们可以更改全局模块所在的路径。

  1. Lists local modules within current dir: npm list
  2. Lists global modules : npm list --globalOR npm list --g// It will list all the top level modules with its dependencies
  3. List only top level(Installed modules) global modules : npm list -g --depth=0
  1. 列出当前目录中的本地模块: npm list
  2. 列出全局模块 : npm list --globalOR npm list --g// 它将列出所有顶级模块及其依赖项
  3. 仅列出顶级(已安装模块)全局模块: npm list -g --depth=0

回答by obimod

One way might be to find the root directory of modules using:

一种方法可能是使用以下方法找到模块的根目录:

npm root
/Users/me/repos/my_project/node_modules

And then list that directory...

然后列出该目录...

ls /Users/me/repos/my_project/node_modules
grunt                   grunt-contrib-jshint

The user-installed packages in this case are grunt and grunt-contrib-jshint

在这种情况下,用户安装的软件包是 grunt 和 grunt-contrib-jshint

回答by rab

To see list of all packages that are installed.

查看已安装的所有软件包的列表。

$ npm ls --parseable | awk '{gsub(/\/.*\//,"",); print}'| sort -u

show parseable of npm packages list https://docs.npmjs.com/cli/ls#parseable

显示可解析的 npm 包列表https://docs.npmjs.com/cli/ls#parseable

回答by pixel 67

I use npm -g outdated --depth=0to list outdated versions
in the global space.

npm -g outdated --depth=0过去常常
在全局空间中列出过时的版本。