How to check the NPM packages installed on your computer

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:

<span class="hl">$ npm list -g
</span>/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:

<span class="hl">vue-app $ npm list
</span>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:

<span class="hl">$ npm list
</span>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
<span class="c1"># ... the rest omitted</span>

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:

<span class="hl">$ npm list --depth<span class="o">=</span><span class="m">0</span>
</span>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. All the Best! 👍

Image 0

Leave a Comment

Your email address will not be published.