查找已安装的npm软件包的版本

问题描述:

如何查找已安装的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.