How to find unused dependencies in npm?
Tags: webdev, javascript, node, npm
Published: 2021-11-11 06:19:27

---
title: How to find unused dependencies in npm?
published: true
date: 2021-09-13 07:19:11 UTC
tags: webdev, javascript, node, npm
canonical_url: https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/
---

NPM has become the most popular package manager over time. It is really helpful and useful to manage the package dependencies of your project. However, over time, as your project keeps growing and new packages get released, there are times when we move on to a better alternative of a package or even stop using a package since we might not require it anymore. In such cases, it is important that we find unused dependencies in our npm’s package.json so that our project does not get bloated up. It also is important to [find outdated packages in npm](https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/ "How to find outdated packages in npm?") and to update or [remove](https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/ "How to remove npm package from a project?") them.

Finding unused packages manually can be a very cumbersome process and might not be efficient too. In such cases, it is recommended to use any tool that would help you find unused dependencies in package.json.

## Here is how you can find unused dependencies in package.json via npm

As I mentioned earlier, finding unused dependencies in package.json manually can be a really tedious task. The easier alternative is to use a tool that would make your task fast and easy. One such tool is [depcheck](https://www.npmjs.com/package/depcheck "Find unused dependencies in npm using Depcheck"). In their own words :

> Depcheck is a tool for analyzing the dependencies in a project to see: how each dependency is used, which dependencies are useless, and which dependencies are missing from package.json
> 
> <cite>https://www.npmjs.com/package/depcheck</cite>

The usage of it is fairly simple. **Run the following command and it would find all the unused dependencies in your package.json** :

```
npx depcheck
```

The command above would execute the package without installing it on your machine. If you are looking **to install the package and run it** then you can **try the following command** :

```
$ npm install -g depcheck

$ depcheck
```

Below is an example of running depcheck on a sample project where I’ve installed bootstrap but haven’t used it.

```
D:\project>npx depcheck
npx: installed 146 in 20.628s
Unused dependencies
* bootstrap
```

In the above example, you can notice that after running the npx depcheck command, it runs the tool and lists the unused dependencies which in my case was only bootstrap. If there were more, it would list all the unused packages in package.json.

Please note that you need to **run the commands in the directory where the package.json file can be found** since by default it looks for the package.json file in the root directory. Also, please note that **you need to have nodejs version 10 or greater installed**.

There are many more options that depcheck provides and you can check them out on their official page at [https://www.npmjs.com/package/depcheck](https://www.npmjs.com/package/depcheck) .

To conclude I would say that it is very easy to find unused dependencies in package.json using npm packages like depcheck etc. It is a good practice to keep the package dependencies on the check and to regularly [remove all the unused package dependencies](https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/ "How to remove npm package from a project?"). It is equally important to [find outdated packages in npm](https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/ "How to find outdated packages in npm?") and to either update them or [remove those outdated packages](https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/ "How to remove npm package from a project?"). Hope you found this article to be useful.

The post [How to find unused dependencies in npm?](https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/) first appeared on [MoreOnFew](https://www.moreonfew.com).