Skip to main content

Automatic cleanup of forgotten node_modules directories

Project description

NodeModulesCleaner (nmc)

CI License

PyPI Python

Issues Stars

codecov

Automatic cleanup of forgotten node_modules directories.

NodeModulesCleaner is a fast, safe, and practical CLI tool that helps you free up disk space by detecting and removing old and unused node_modules folders from your system.

It recursively scans your filesystem, identifies abandoned node_modules directories based on access time and size, and optionally deletes them — safely and efficiently.


✨ Features

  • 🔍 Recursive directory scanning
  • 🕒 Filter by last access time (--days)
  • 📦 Filter by minimum directory size (--min-size)
  • 🔎 Dry-run mode (preview before deleting)
  • 🤖 Non-interactive automation mode (--yes)
  • ⚡ Very fast (no heavy indexing or hashing)
  • 🧪 Fully testable architecture (core separated from CLI)
  • 🧩 Clean, maintainable and extensible design

📦 Why does this exist?

JavaScript projects often accumulate hundreds of megabytes or even gigabytes inside node_modules.

Over time, many of these folders become abandoned, consuming large amounts of disk space and slowing down backups, indexing, and file searches.

This tool helps you:

  • Clean forgotten dependencies
  • Reclaim disk space
  • Keep your development environment tidy
  • Automate periodic cleanup (cron jobs, CI pipelines, scripts)

🚀 Installation

Using pip (recommended)

pip install nodemodulescleaner

⚡ Quick Usage

Scan your home directory:

nmc ~

Preview what would be deleted:

nmc ~ --dry-run

Delete folders not accessed in the last 30 days and larger than 200 MB:

nmc ~ --days 30 --min-size 200

Fully automated cleanup (no confirmation prompt):

nmc ~ --days 60 --min-size 100 -y

⚙️ CLI Options

usage: nmc [path] [options]

positional arguments:
  path                Directory to scan (default: current directory)

options:
  --days N            Ignore node_modules accessed within the last N days (default: 30)
  --min-size MB       Minimum size in MB (default: 0)
  --dry-run           Simulate the cleanup without deleting anything
  -y, --yes           Automatically confirm deletion (non-interactive mode)

🛡️ Safety First

Before deleting anything, the tool:

  • Lists all matching directories
  • Shows total recoverable disk space
  • Requires explicit confirmation (unless -y is used)

Always test first:

nmc <path> --dry-run

🧑‍💻 Developer Guide (Dev)

This section is for contributors and developers who want to run, test, or extend the project.


📁 Project Structure

nmc/
 ├── core.py     # Business logic (scan + filters + cleanup)
 ├── cli.py      # CLI interface (argparse + UX)
 └── __init__.py

This separation ensures:

  • High testability
  • Clean architecture
  • Easy extensibility
  • Stable CLI behavior

🔧 Local Development Setup

1️⃣ Clone the repository

git clone https://github.com/hbisneto/NodeModulesCleaner.git
cd NodeModulesCleaner

2️⃣ Create a virtual environment

python3 -m venv venv
source venv/bin/activate

3️⃣ Install in editable mode

pip install -e .

This allows immediate reflection of local code changes.


▶ Running Locally

nmc ~/projects --dry-run

or:

python -m nmc.cli ~/projects --dry-run

🧪 Running Tests

pytest -v

The architecture guarantees:

  • No interactive input during tests
  • No filesystem pollution
  • Fully deterministic execution

🏗 Architecture Overview

Core Logic → nmc/core.py

Handles:

  • Directory scanning
  • Filtering logic
  • Cleanup execution

No user interaction. No printing.


CLI Interface → nmc/cli.py

Handles:

  • Argument parsing
  • User prompts
  • Output formatting
  • UX flow

This separation enables:

  • Stable CI pipelines
  • Easy automation
  • Reliable testing
  • Low bug surface

🤝 Contributing

Contributions are very welcome!

If you'd like to help improve NodeModulesCleaner, please check out the open issues on GitHub:

👉 https://github.com/hbisneto/NodeModulesCleaner/issues

There you will find:

  • 🐛 Bug reports
  • 🚀 Feature requests
  • 🧩 Planned enhancements
  • 🏗 Architecture improvements
  • 🧪 Testing and CI ideas

If you have a new idea, feel free to open a new issue or start a discussion.

Every contribution — from code to documentation, testing, or ideas — is highly appreciated! ❤️


📜 License

MIT License — feel free to use, modify, and distribute.


⭐ Support

If this tool helped you, please leave a ⭐ on GitHub — it really helps!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nodemodulescleaner-1.0.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nodemodulescleaner-1.0.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file nodemodulescleaner-1.0.0.0.tar.gz.

File metadata

  • Download URL: nodemodulescleaner-1.0.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.0

File hashes

Hashes for nodemodulescleaner-1.0.0.0.tar.gz
Algorithm Hash digest
SHA256 7186960bf164c108a3d4602e2f696fbbb311e8aac9f5e704e720c889f2e24e05
MD5 3676696dd8cb4ee1e093f7d0eecfa164
BLAKE2b-256 add8a2ab0f41c237928d0a6dce33e5f5dc949e0bcecd48fdf2f216f947e158da

See more details on using hashes here.

File details

Details for the file nodemodulescleaner-1.0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nodemodulescleaner-1.0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f166b75fd905865d8aa3e4ec67952fb14d943da8e138a776459dbdd543c4fe47
MD5 8e47f7ddaeff045f6b8b875dc74302a9
BLAKE2b-256 a9774b1862ed9873c958fc80720d52e9d0b8efaf56ba3dbdb20417c0911e1aae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page