Recursively manage
node_modules
folders
Installation
# Install globally via npm:
npm install -g clean-node-module
# Or use npx without install:
npx clean-node-module <action> [path]
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) |
clean-node-module size ./my-project
Outputs the size of each node_modules
directory under ./my-project
, in MB.
clean-node-module count /path/to/repo
Lists how many node_modules
folders exist and how many subdirectories each has.
# 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.
- Uses Node.js
fs/promises.readdir
withwithFileTypes
to efficiently walk directories. - Detects any folder named
node_modules
at 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.
- 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.
This project is licensed under the MIT License. See the LICENSE file for details.