Use the npm list
command to get the versions of all locally installed npm packages.
$npm list |-- [email protected] |-- [email protected] |-- [email protected] | |-- [email protected] | | |-- [email protected] | |-- [email protected] |-- [email protected] |-- [email protected] | |-- [email protected] | |-- [email protected] deduped | |-- [email protected] deduped | |-- [email protected] deduped | |-- [email protected] | |-- [email protected] deduped | |-- [email protected] | | |-- [email protected] | |-- [email protected] deduped | |-- [email protected] deduped | |-- [email protected] | | |-- [email protected] deduped | | |-- [email protected] deduped
You can see that the versions of all the locally installed packages and their dependencies are shown in a tree view.
When you pass --depth=0
to the npm list
command, then the dependencies of the packages are not shown.
$npm list --depth=0 |-- [email protected] |-- [email protected]
Note: In NPM version 8.x, the npm list
command does not show the dependencies of the packages until you pass --all
flag to it.
You can also find the version of an installed npm package by passing the package name to the npm list
command.
$npm list express /Users/mohitnatani |-- [email protected]
The version of the express
package installed in the project is 4.18.1
.
When a package is not installed, and you run the npm list package-name
command, then empty is shown in the output.
$npm list mongoose /Users/mohitnatani |-- (empty)
If you are interested in finding the versions of all globally installed packages, then provide -g
flag to the npm list
command.
$npm list -g /usr/local/lib |-- [email protected] |-- [email protected] | |-- [email protected] | | |-- [email protected] | | | |-- [email protected] | | |-- [email protected] | |-- [email protected] | |-- [email protected] | | |-- [email protected] | | |-- [email protected] deduped | | |-- [email protected] deduped | | |-- [email protected] deduped | | |-- [email protected] | | |-- [email protected] deduped | | |-- [email protected] | | | |-- [email protected] | | |-- [email protected] deduped | | |-- [email protected] deduped
If you pass --depth=0
, then dependencies of the packages will not be shown.
$npm list -g --depth=0 /usr/local/lib |-- [email protected] |-- [email protected] |-- [email protected] |-- [email protected] |-- [email protected] |-- [email protected]
By providing the package name to the npm list -g
command, you can get the version of that globally installed npm package.
$npm list -g nodemon /usr/local/lib |-- [email protected]
From the output, you can infer that the version 2.0.16 of nodeman package is installed.
If the package is not installed globally then it will return empty.
$npm list -g express /usr/local/lib |-- (empty)