小能豆

Find the version of an installed npm package

javascript

How can I find the version of an installed Node.js or npm package?

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

How do I get the installed version?


阅读 82

收藏
2023-12-25

共1个答案

小能豆

To find the installed version of a specific Node.js package, you can use the npm list command along with the --depth and --global options if needed. Here’s an example:

npm list --global <package-name>

Replace <package-name> with the name of the package for which you want to check the installed version.

If the package is installed locally (in your project), you can omit the --global option:

npm list <package-name>

This command will display a tree-like structure of installed packages in your project, and you can easily find the version of the specified package.

If you want a more concise output showing only the version number, you can use the --depth=0 option:

npm list --global --depth=0 <package-name>

or

npm list --depth=0 <package-name>

This will show only the top-level dependencies along with their versions.

Remember to replace <package-name> with the actual name of the package you are interested in.

2023-12-25