如何仅在npm
中列出用户安装的软件包?当我做npm -g list
时,它会输出每个包及其依赖项,这不是我想要的。
这也很有效:npm list -g --depth=0
查看已安装的所有软件包的列表。
$ npm ls --parseable | awk '{gsub(/\/.*\//,"",$1); print}'| sort -u
显示可解析的npm包列表https://docs.npmjs.com/cli/ls#parseable
我使用npm -g outdated --depth=0
列出过时的版本
在全球空间。
Node_modules包含用户安装的软件包,因此将目录更改为node_modules并列出项目。 Core Modules在lib/
文件夹的节点源中定义。
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
使用npm list
并使用grep
过滤包含
例:
npm list -g | grep name-of-package
作为简写,您可以运行:
npm ls -g --depth=0
你可以尝试NPM Desktop manager
只需单击一下,即可在dev
或global
状态下安装/卸载软件包。
对于本地模块使用npm list --depth 0
Foe Global模块npm list -g --depth 0
您可以使用以下命令获取所有全局安装模块的列表:
ls `npm root -g`
截至2015年12月13日
虽然我发现接受的答案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.
对于本地模块:
npm list --depth=0
对于全球模块:
npm list -g --depth=0
我更喜欢带有友好gui的工具!
我使用了npm-gui
,它提供了本地和全球包的列表
包裹在https://www.npmjs.com/package/npm-gui和https://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 list --depth=0
对于全局依赖项,请使用:
npm list -g --depth=0
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。
Node具有本地模块和全局模块的概念
本地模块位于当前项目目录中。
全局模块通常位于用户的主目录中,但我们可以更改全局模块所在的路径。
npm list
npm list --global
或npm list --g
//它将列出所有顶级模块及其依赖项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