How to check the npm version installed on your computer

Once you installed Node.js on your computer, you can check the version of npm that was bundled with it.

The command to check your npm version is npm -v or npm --version. Type it in your terminal and you should see the following output:

$ npm -v
8.1.0
# or
$ npm --version
8.1.0

The output above means npm has been installed successfully on your computer.

Next, let’s see how you find the version of an installed npm package.

Find the version of an installed npm package

The version of npm packages installed on your computer can be found by running the npm list command.

First, navigate to the root directory of your project, then run the npm list command.

You should see the output below in your terminal:

$ npm list
[email protected] /Users/nsebhastian/Desktop/DEV/n-app
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

The output above shows the packages installed in the node_modules/ folder.

If you’re using an older npm version, then you might see the list of all modules installed, including the dependencies of your top-level modules.

For example, here’s the output when I run npm list using npm v6:

$ npm list
[email protected] /Users/nsebhastian/Desktop/DEV/n-app
├─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
# ...

The output above also shows the dependency packages installed for your modules, such as object-assign and vary installed as dependencies of the cors package.

To make npm show only the top-level modules, add the --depth=0 option to the npm list command:

$ npm list --depth=0
[email protected] /Users/nsebhastian/Desktop/DEV/n-app
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

In the latest npm version, --depth=0 is the default option automatically added to the command, so you don’t need to add it anymore.

Check the version of globally installed npm packages

To check the version of globally installed npm packages, run the npm list command with the -g or --global option added.

Here’s an example:

$ npm list -g
/Users/nsebhastian/node/lib
├── [email protected]
└── [email protected]

For older npm versions, you might want to add --depth=0 option to show only top-level modules:

npm list -g --depth=0
/Users/nsebhastian/node/lib
├── [email protected]
└── [email protected]

And that’s how you check the versions of globally installed npm packages.

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.