我如何列出用户安装/环境包只在npm?

当我执行npm -g list时,它会输出每个包及其依赖项。相反,我希望看到包安装在当前工作的项目或环境中。


当前回答

对于项目依赖使用:

npm list --depth=0

对于全局依赖使用:

npm list -g --depth=0

其他回答

npm list -g --depth=0

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

对于项目依赖使用:

npm list --depth=0

对于全局依赖使用:

npm list -g --depth=0

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

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。

使用npm列表和使用grep过滤包含

例子:

npm list -g | grep name-of-package

你可以试试NPM桌面管理器:

只需单击一下,您就可以在dev或全局状态下安装/卸载包。