clean-node-module
v1.0.6
Published
Recursively purge all node_modules folders
Readme
clean-node-module
Recursively manage
node_modulesfolders
Installation
# Install globally via npm:
npm install -g clean-node-module
# Or use npx without install:
npx clean-node-module <action> [path]Commands & Options
All commands accept an optional [path] argument. If omitted, the script runs against the current working directory.
| Action | Description |
| -------- | ----------------------------------------------------------------------- |
| size | Display the total size of each node_modules found |
| count | Show the number of node_modules folders plus subfolders each contains |
| delete | Recursively delete all node_modules folders (default) |
Usage Examples
1. Display Sizes
clean-node-module size ./my-projectOutputs the size of each node_modules directory under ./my-project, in MB.
2. Count Folders
clean-node-module count /path/to/repoLists how many node_modules folders exist and how many subdirectories each has.
3. Delete All node_modules
# Default action is delete
clean-node-module /path/to/monorepo
# Or explicitly:
clean-node-module delete .Recursively purges every node_modules folder under the specified path.
How It Works
- Uses Node.js
fs/promises.readdirwithwithFileTypesto efficiently walk directories. - Detects any folder named
node_modulesat any depth and gathers its path. - Depending on the action, it either computes directory size (
fs.stat), counts subdirectories, or removes the folder (fs.rm). - Runs asynchronously, so it won’t block your terminal even in large projects.
Contributing
- Fork the repository.
- Create a feature branch:
git checkout -b feature/your-feature. - Make your changes and commit:
git commit -m 'feat: add XYZ'. - Push to the branch:
git push origin feature/your-feature. - Open a Pull Request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
