How to check the npm packages installed on your computer

Posted on Jun 03, 2022

Learn to check what npm packages are installed globally or locally on your computer

When you add the --global or -g flag when running the npm install command, then the package will be installed globally.

Without the --global flag, then the npm package will be installed locally inside the node_modules/ folder of the current directory.

To check for all packages that are installed globally, you need to run the npm list command with the --global or -g flag as shown below:

npm list -g

The output in the terminal reveals the package name and the version installed as follows:

$ npm list -g
/Users/nsebhastian/.nvm/versions/node/v16.13.0/lib
├── live-server@1.2.2
├── npm@8.1.0
├── react-native-cli@2.0.1
└── sequelize-cli@6.4.1

To check for all packages that are installed locally, run the npm list command from the root directory of your project.

Suppose you have a project called vue-app. You need to run npm list from the vue-app/ folder like this:

vue-app $ npm list
vue-app@0.1.0 /Users/nsebhastian/Desktop/DEV/vue-app
├── @babel/core@7.18.2
├── @babel/eslint-parser@7.18.2
├── @vue/cli-plugin-babel@5.0.4
├── @vue/cli-plugin-eslint@5.0.4
├── @vue/cli-service@5.0.4
├── core-js@3.22.8
├── eslint-plugin-vue@8.7.1
├── eslint@7.32.0
└── vue@3.2.36

Keep in mind that if you’re using npm below version 7, then the npm list command will also show the related dependencies below the first level.

Here’s the same output of the vue-app dependencies using npm version below 7:

$ npm list
vue-app@0.1.0 /Users/nsebhastian/Desktop/DEV/vue-app
├─┬ @babel/core@7.18.2
│ ├─┬ @ampproject/remapping@2.2.0
│ │ ├─┬ @jridgewell/gen-mapping@0.1.1
│ │ │ ├── @jridgewell/set-array@1.1.1
│ │ │ └── @jridgewell/sourcemap-codec@1.4.13
│ │ └─┬ @jridgewell/trace-mapping@0.3.13
│ │   ├── @jridgewell/resolve-uri@3.0.7
│ │   └── @jridgewell/sourcemap-codec@1.4.13 deduped
│ ├─┬ @babel/code-frame@7.16.7
│ │ └─┬ @babel/highlight@7.17.12
│ │   ├── @babel/helper-validator-identifier@7.16.7 deduped
│ │   ├── chalk@2.4.2 deduped
│ │   └── js-tokens@4.0.0
│ ├─┬ @babel/generator@7.18.2
│ │ ├── @babel/types@7.18.4 deduped
# ... the rest omitted

As you can see, the default output from npm list command above is intimidating. It’s hard to figure out what’s installed in your project.

When you only need the top-level dependencies, add the --depth=0 option to the command:

$ npm list --depth=0
v-app@0.1.0 /Users/nsebhastian/Desktop/DEV/v-app
├── @babel/core@7.18.2
├── @babel/eslint-parser@7.18.2
├── @vue/cli-plugin-babel@5.0.4
├── @vue/cli-plugin-eslint@5.0.4
├── @vue/cli-service@5.0.4
├── core-js@3.22.8
├── eslint-plugin-vue@8.7.1
├── eslint@7.32.0
└── vue@3.2.36

Since npm version 7, the --depth=0 option has been added to the npm list command by default.

Now you know how to check what npm packages are installed on your computer, both globally and locally. Nice work! 👍

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.