Backend Development 3 min read

Using npm-check and ESLint to Detect and Remove Unused npm Packages

This guide explains how to install and use npm-check together with ESLint to identify outdated, incorrect, or unused dependencies in a Node.js project, remove unnecessary require statements, and ensure that only needed packages remain in the codebase.

System Architect Go
System Architect Go
System Architect Go
Using npm-check and ESLint to Detect and Remove Unused npm Packages

As a project evolves, it is common to accumulate dependency packages that were once needed but are no longer used, and ignoring them is not a good practice.

npm install -g npm-check installs npm-check , a tool that scans the current directory for outdated, incorrect, or unused npm packages.

Running npm-check automatically evaluates the project's dependencies.

npm-check determines whether a package is used by checking for a require('package') statement in the source files; if such a statement exists, the package will not be marked as unused even if it is never referenced elsewhere.

For example:

const lodash = require('lodash');

Because the require call is present, npm-check will consider lodash as used.

To catch cases where a package is required but never actually used, you can employ ESLint with the no-unused-vars rule.

Install ESLint globally with npm install -g eslint , then create an .eslintrc.js configuration file (the original article includes a screenshot of the config).

Run the linting command:

eslint --config .eslintrc.js ./

This checks all files in the current directory for variables—including imported packages—that are defined but never used. After removing such unused variables and references, running npm-check again will correctly list the dependencies that are truly unnecessary.

Both npm-check and ESLint offer many more features; consult their official documentation for deeper usage.

dependency managementnodejsnpmESLintnpm-checkUnused Dependencies
System Architect Go
Written by

System Architect Go

Programming, architecture, application development, message queues, middleware, databases, containerization, big data, image processing, machine learning, AI, personal growth.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.