How to check the npm version installed on your computer

Posted on May 26, 2022

Learn 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
n-app@1.0.0 /Users/nsebhastian/Desktop/DEV/n-app
├── cors@2.8.5
├── express@4.18.1
├── gulp@3.9.1
├── jest@28.1.0
├── mocha@10.0.0
└── vue@2.6.14

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
n-app@1.0.0 /Users/nsebhastian/Desktop/DEV/n-app
├─┬ cors@2.8.5
│ ├── object-assign@4.1.1
│ └── vary@1.1.2
├─┬ express@4.18.1
│ ├─┬ accepts@1.3.8
│ │ ├─┬ mime-types@2.1.35
│ │ │ └── mime-db@1.52.0
│ │ └── negotiator@0.6.3
│ ├── array-flatten@1.1.1
# ...

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
n-app@1.0.0 /Users/nsebhastian/Desktop/DEV/n-app
├── cors@2.8.5
├── express@4.18.1
├── gulp@3.9.1
├── jest@28.1.0
├── mocha@10.0.0
└── vue@2.6.14

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
├── npm@6.14.12
└── react-native-cli@2.0.1

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
├── npm@6.14.12
└── react-native-cli@2.0.1

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

Level up your programming skills

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

No spam. Unsubscribe anytime.