npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

npm-diet

v1.0.0

Published

Automatically remove unused npm dependencies. Lost 500MB in 30 seconds.

Downloads

11

Readme

npm-diet 🍃

Stop paying for unused dependencies.

npm version License: MIT

Automatically detect and remove unused npm dependencies. Reclaim disk space, reduce bundle size, speed up installs.

😱 The Problem

$ du -sh node_modules
847MB   node_modules

# Half of those packages? You're not even using them.

Every unused dependency:

  • 💾 Wastes disk space
  • 📦 Increases bundle size
  • ⏱️ Slows down npm install
  • 🐛 Adds security vulnerabilities
  • 😵 Makes package.json unreadable

✨ The Solution

$ npx npm-diet

🔍 npm-diet - Scanning for unused dependencies...

Found 12 unused dependencies:

Dependencies:
  - moment
  - lodash
  - axios
  - express
  - request
  - body-parser
  - ...

💾 Space to reclaim: 127.5 MB

Remove these packages? (y/N): y

🗑️  Removing unused dependencies...

✓ Removed 12 dependencies
✓ Removed 3 devDependencies

✨ Freed up 127.5 MB!

Your node_modules just lost weight.

🚀 Quick Start

# Scan and preview (dry run)
npx npm-diet --dry-run

# Scan and remove (interactive)
npx npm-diet

# Auto-remove without confirmation
npx npm-diet --auto

💡 How It Works

  1. Scans all .js, .jsx, .ts, .tsx files
  2. Detects import and require() statements
  3. Compares with package.json dependencies
  4. Finds packages you installed but never imported
  5. Removes them (after your confirmation)

📊 What Gets Detected

Detects these imports:

// ES6 imports
import React from 'react';
import { useState } from 'react';
import * as axios from 'axios';

// CommonJS requires
const express = require('express');
const { join } = require('path');

// Dynamic imports
const module = await import('lodash');

// Side-effect imports
import 'some-polyfill';

Handles scoped packages:

import babel from '@babel/core';          // Detects @babel/core
import parser from '@babel/core/lib/parse'; // Detects @babel/core

Ignores relative imports:

import utils from './utils';     // Ignored
import config from '../config';  // Ignored

🎯 Usage Modes

1. Dry Run (Preview Only)

npx npm-diet --dry-run
# or
npx npm-diet -d

Shows what would be removed without actually removing anything.

2. Interactive (Default)

npx npm-diet

Asks for confirmation before removing packages.

3. Auto Mode

npx npm-diet --auto
# or
npx npm-diet -y

Removes packages automatically without confirmation.

⚙️ Installation

# Run directly (recommended)
npx npm-diet

# Or install globally
npm install -g npm-diet
diet

🔍 What Gets Scanned

File types:

  • .js - JavaScript
  • .jsx - React JSX
  • .ts - TypeScript
  • .tsx - React TypeScript
  • .mjs - ES Modules
  • .cjs - CommonJS

Excluded directories:

  • node_modules/
  • dist/
  • build/
  • .next/
  • coverage/

🎨 Example Output

$ npx npm-diet

🔍 npm-diet - Scanning for unused dependencies...

Found 8 unused dependencies:

Dependencies:
  - moment (you switched to date-fns)
  - request (deprecated anyway)
  - lodash (using native methods now)
  - body-parser (built into Express 4.16+)
  - morgan (removed logging)

DevDependencies:
  - @types/node (not using TypeScript anymore)
  - eslint-plugin-react (switched to Biome)
  - prettier (switched to Biome)

💾 Space to reclaim: 47.3 MB

⚠️  This will uninstall the packages above
Add --dry-run to preview without removing
Add --auto to skip confirmation

Remove these packages? (y/N): y

🗑️  Removing unused dependencies...

✓ Removed 5 dependencies
✓ Removed 3 devDependencies

✨ Freed up 47.3 MB!

⚠️ Limitations

May miss:

  • ❌ Packages only used in config files (webpack.config.js, .eslintrc.js)
  • ❌ Packages required by CLI tools (not imported in code)
  • ❌ Packages loaded via string variables (require(variableName))
  • ❌ Peer dependencies
  • ❌ Packages used in .gitignored files

Always review the list before confirming removal.

🛡️ Safety Features

  • ✅ Dry run mode by default shows what would be removed
  • ✅ Interactive confirmation before removing
  • ✅ Uses npm uninstall (safe and reversible)
  • ✅ Never touches node_modules/ directly
  • ✅ Only modifies package.json via npm

If you accidentally remove something: Just npm install package-name it back.

💡 Pro Tips

Run monthly

# Add to your workflow
npx npm-diet --dry-run  # Check what's unused

Before deploys

# Clean up before shipping
npx npm-diet --auto
npm run build

After refactors

# Replaced moment with date-fns?
npx npm-diet  # Removes moment automatically

CI/CD integration

# In your CI pipeline
npx npm-diet --dry-run
# Fails if unused deps found (exit code 1)

🎯 Use Cases

For Developers:

  • ✅ Clean up after removing features
  • ✅ Remove packages after switching libraries
  • ✅ Audit unused dependencies monthly

For Teams:

  • ✅ Reduce node_modules bloat
  • ✅ Speed up CI/CD installs
  • ✅ Lower hosting costs (smaller deploys)

For Projects:

  • ✅ Reduce security surface area
  • ✅ Improve bundle size
  • ✅ Faster npm install times

📈 Real Results

Project A (React app):
- Before: 847 MB node_modules
- After: 612 MB node_modules
- Saved: 235 MB (28%)

Project B (Express API):
- Before: 312 MB node_modules
- After: 187 MB node_modules
- Saved: 125 MB (40%)

🔥 Why This Exists

We've all been there:

  1. Install package for one feature
  2. Remove that feature months later
  3. Forget to uninstall the package
  4. Repeat 50 times
  5. 800 MB node_modules folder

npm-diet fixes this automatically.

👤 Author

Daniel Shashko

📄 License

MIT © Daniel Shashko


🍃 Put Your Dependencies on a Diet

npx npm-diet

Lose the weight. Keep the features.