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

问题描述 投票:494回答:16

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

node.js npm package-managers
16个回答
1053
投票

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

  • npm:Node包管理器命令行工具
  • list -g:显示在用户文件夹中找到的每个包的树(没有-g选项,它只显示当前目录的包)
  • depth 0 / - depth = 0:避免在树视图中包含每个包的依赖关系

6
投票

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

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

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


4
投票

我使用npm -g outdated --depth=0列出过时的版本 在全球空间。


3
投票

Node_modules包含用户安装的软件包,因此将目录更改为node_modules并列出项目。 Core Moduleslib/文件夹的节点源中定义。

Example:

     example@example:~/:~/node_modules$ ls
     express  maxmind-native  node-whois  socket.io  ua-parser-js
     geoip    mongoskin       pdfkit      tail       zeromq
     maxmind  nodemailer      request     ua-parser  zmq

2
投票

使用npm list并使用grep过滤包含

例:

npm list -g | grep name-of-package

1
投票

作为简写,您可以运行:

npm ls -g --depth=0

1
投票

你可以尝试NPM Desktop manager NPM Desktop manager

只需单击一下,即可在devglobal状态下安装/卸载软件包。


0
投票

对于本地模块使用npm list --depth 0

Foe Global模块npm list -g --depth 0

Example local npm module Example global npm module


122
投票

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

ls `npm root -g`


96
投票

截至2015年12月13日

npm list illustration

虽然我发现接受的答案100%正确,有用,但希望根据我自己的经验对其进行一些扩展,并希望为了其他人的利益。 (这里我可以互换地使用包和模块这两个术语)

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

npm list -g --depth=0

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

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

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

npm view <module_name> versions

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

对于最新的远程版本:

npm view <module_name> version  

注意,版本是单数。

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

npm outdated -g --depth=0

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

npm update -g <package>

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

npm update -g

(但是,对于小于2.6.1的npm版本,请参阅this link,因为有一个特殊的脚本建议全局更新所有包)。

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


52
投票

对于本地模块:

npm list --depth=0

对于全球模块:

npm list -g --depth=0

30
投票

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

我使用了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

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

npm-gui


17
投票

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

npm list --depth=0

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

npm list -g --depth=0

16
投票
npm ls

npm list只是npm ls的别名

对于扩展信息使用

npm la    
npm ll

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

npm ls --depth=0

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

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

json格式显示信息

npm ls --json=true

默认值为false

npm ls --json=false

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

npm ls --long=true

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

npm ls --parseable=true

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

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

完整的文档,你可以找到here


8
投票

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

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

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

  1. 列出当前目录中的本地模块:npm list
  2. 列出全局模块:npm list --globalnpm list --g //它将列出所有顶级模块及其依赖项
  3. 仅列出顶级(已安装模块)全局模块:npm list -g --depth=0

7
投票

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

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

然后列出该目录......

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

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

© www.soinside.com 2019 - 2024. All rights reserved.