/

How to Find the Installed Version of an npm Package

How to Find the Installed Version of an npm Package

Knowing the version of a specific package installed in your application is essential for various reasons. Here are a few methods to help you find out the installed version of an npm package.

To see the latest version of all the npm packages installed, along with their dependencies, you can use the following command in your terminal:

1
npm list

For example:

1
2
3
4
5
6
7
8
9
10
11
12
❯ npm list
/Users/flavio/dev/node/cowsay
└─┬ [[email protected]](/cdn-cgi/l/email-protection)
├── [[email protected]](/cdn-cgi/l/email-protection)
├─┬ [[email protected]](/cdn-cgi/l/email-protection)
│ ├── [[email protected]](/cdn-cgi/l/email-protection)
│ └── [[email protected]](/cdn-cgi/l/email-protection)
├─┬ [[email protected]](/cdn-cgi/l/email-protection)
│ ├── [[email protected]](/cdn-cgi/l/email-protection)
│ └─┬ [[email protected]](/cdn-cgi/l/email-protection)
│ └── [[email protected]](/cdn-cgi/l/email-protection)
└── [[email protected]](/cdn-cgi/l/email-protection)

Another option is to open the package-lock.json file and visually scan for the package version. However, this method can be time-consuming.

If you want to check globally installed packages, you can use the -g flag with the npm list command. For example:

1
npm list -g

To get only the top-level packages, which are the ones specified in your package.json, you can run the following command:

1
npm list --depth=0

For example:

1
2
3
❯ npm list --depth=0
/Users/flavio/dev/node/cowsay
└── [[email protected]](/cdn-cgi/l/email-protection)

If you want to find the version of a specific package, you can use the package name as an argument with the npm list command. For example:

1
npm list <package_name>

For example:

1
2
3
❯ npm list cowsay
/Users/flavio/dev/node/cowsay
└── [[email protected]](/cdn-cgi/l/email-protection)

This method also works for the dependencies of the packages you have installed. For example:

1
2
3
4
5
❯ npm list minimist
/Users/flavio/dev/node/cowsay
└─┬ [[email protected]](/cdn-cgi/l/email-protection)
└─┬ [[email protected]](/cdn-cgi/l/email-protection)
└── [[email protected]](/cdn-cgi/l/email-protection)

If you want to check the latest available version of a package in the npm repository, you can use the npm view command followed by the package name and the keyword version. For example:

1
npm view [package_name] version

For example:

1
2
3
❯ npm view cowsay version

1.3.1

By using these methods, you can easily find the installed version of the npm packages in your application.

tags: [“npm”, “package”, “version”, “dependencies”]