查找已安装的 npm 包的版本 [英] Find the version of an installed npm package
问题描述
如何查找已安装的 node.js/npm 包的版本?
How to find the version of an installed node.js/npm package?
这会打印 npm 本身的版本:
This prints the version of npm itself:
npm -v <package-name>
这会打印一个神秘的错误:
This prints a cryptic error:
npm version <package-name>
这会在注册表上打印软件包版本(即可用的最新版本):
This prints the package version on the registry (i.e. the latest version available):
npm view <package-name> version
我如何获得安装版本?
推荐答案
npm list
用于本地包或 npm list -g
用于全局安装的包.
npm list
for local packages or npm list -g
for globally installed packages.
您可以通过将名称作为参数传递来查找特定包的版本.例如,npm list grunt
将导致:
You can find the version of a specific package by passing its name as an argument. For example, npm list grunt
will result in:
projectName@projectVersion /path/to/project/folder
└── grunt@0.4.1
或者,您可以只运行 npm list
而不将包名称作为参数传递来查看所有包的版本:
Alternatively, you can just run npm list
without passing a package name as an argument to see the versions of all your packages:
├─┬ cli-color@0.1.6
│ └── es5-ext@0.7.1
├── coffee-script@1.3.3
├── less@1.3.0
├─┬ sentry@0.1.2
│ ├── file@0.2.1
│ └── underscore@1.3.3
└── uglify-js@1.2.6
您还可以添加 --depth=0
参数以列出已安装的软件包,而无需它们的依赖项.
You can also add --depth=0
argument to list installed packages without their dependencies.
这篇关于查找已安装的 npm 包的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!