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?
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
--depth
--global
npm list --global <package-name>
Replace <package-name> with the name of the package for which you want to check the installed version.
<package-name>
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:
--depth=0
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.