Get the Installed Version of an npm Package
When you want to report a bug in an npm package, most packages ask you for what
version of the package you're using. Just looking at
package.json isn't enough
if you're using semver ranges. If your
package.json file says
'5.x' is not a version, it's a range.
To get what version of Mongoose you currently have installed, run
npm list mongoose,
npm ls mongoose for short. For example, here's the result of running
npm list mongoose from the Mastering JS git repo.
It shows that the currently installed version of Mongoose is v5.10.6.
$ npm list mongoose masteringjs.io@ /path/to/masteringjs.io └── firstname.lastname@example.org $
Listing Multiple Packages
npm list without a package name prints all installed packages, including
their dependencies, with version numbers. The output of
npm list is typically too big
to read, but the beginning looks like this:
masteringjs.io@ /path/to/masteringjs.io ├── @email@example.com ├─┬ @firstname.lastname@example.org │ ├─┬ @email@example.com │ │ ├── @firstname.lastname@example.org ...
However, you can make the output more usable by using
only show the version of top-level dependencies.
npm list --depth=0
Below is the beginning of the output of
npm list --depth=0 for the Mastering JS
masteringjs.io@ /path/to/masteringjs.io ├── @email@example.com ├── @firstname.lastname@example.org ├── @email@example.com ├── firstname.lastname@example.org ├── email@example.com ├── firstname.lastname@example.org ├── email@example.com ├── firstname.lastname@example.org ├── email@example.com ├── firstname.lastname@example.org