Sentry Answers>Node.js>

Find the version of an installed npm package

Find the version of an installed npm package

Naveera A.

The ProblemJump To Solution

Most modern JavaScript apps use a bunch of third party packages. Many packages are installed globally too.

How do you find the installed versions of the various npm packages?

The Solution

All locally installed npm packages are listed in the package-lock.json file. For a smaller project, you can take a quick look at this file.

An easier way to find the installed versions of npm packages that doesn’t require so much visual scanning is to use the built-in command list:

Click to Copy
$ npm list

This command will print all the versions of packages that are installed in the current directory to stdout, like so:

Click to Copy
$ npm list projectName@projectVersion /path/to/project/folder ├── futil@1.69.0 └── lodash@4.17.21

If you want to see all the dependencies of manually installed packages and their versions, you can use --all :

Click to Copy
$ npm list --all projectName@projectVersion /path/to/project/folder ├─┬ futil@1.69.0 │ ├─┬ babel-polyfill@6.26.0 │ │ ├─┬ babel-runtime@6.26.0 │ │ │ ├── core-js@2.6.12 deduped │ │ │ └── regenerator-runtime@0.11.1 │ │ ├── core-js@2.6.12 │ │ └── regenerator-runtime@0.10.5 │ └── lodash@4.17.21 deduped └── lodash@4.17.21

You can also control the depth of level to show by using --depth. For example, using --depth=1 will show the following:

Click to Copy
$ npm list --depth=1 projectName@projectVersion /path/to/project/folder ├─┬ futil@1.69.0 │ ├── babel-polyfill@6.26.0 │ └── lodash@4.17.21 deduped └── lodash@4.17.21

Notice that any dependencies that are more than two levels deep are removed from the tree.

If you want to take a look at globally installed packages, you can use -g, like so:

Click to Copy
$ npm list -g /path/to/node/v16.15.1/lib ├── corepack@0.10.0 └── npm@8.12.1

To find the version of a specific package, specify its name:

Click to Copy
$ npm list futil projectName@projectVersion /path/to/project/folder └── futil@1.69.0

To check the latest available version of the package on the npm repository, use the view option:

Click to Copy
$ npm view futil --version 8.12.1

Besides these, there are a few other options that can be used with list. You can take a look at all available options in the official documentation.

  • Community SeriesIdentify, Trace, and Fix Endpoint Regression Issues
  • ResourcesBackend Error Monitoring 101
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty Treats for Web Developers brought to you by Sentry. Web development tips and tricks hosted by Wes Bos and Scott Tolinski

    Listen to Syntax

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.