A simple and efficient Node.js CLI tool to recursively find and delete node_modules directories from your project and its subdirectories.
nmclean is designed to help developers clean up their projects by removing all node_modules folders. It starts from the current working directory and recursively searches through all subdirectories to locate and delete any node_modules directories it finds. This is particularly useful for freeing up disk space or preparing a project for archiving/deployment.
Install globally via npm:
npm install -g nmcleanOr run directly with npx:
npx nmcleanAfter installation, simply run the command in your project directory:
nmcleanThe tool will:
- Start scanning from the current working directory
- Recursively search all subdirectories
- Delete any
node_modulesfolders found - Display progress with colored output
- Handle permission errors gracefully
--- Node Modules Cleaner (nmclean) ---
Scanning: /path/to/your/project
Deleting: /path/to/your/project/node_modules
Deleting: /path/to/your/project/subdir/node_modules
[nmclean] Success: All node_modules removed.
- Recursive Deletion: Cleans
node_modulesfrom the current directory and all subdirectories - Safe Operation: Handles permission errors and missing directories gracefully
- Colored Output: Provides clear visual feedback during the cleaning process
- Fast and Efficient: Uses Node.js built-in file system operations for optimal performance
- Zero Dependencies: Lightweight with no external dependencies
The tool uses Node.js's fs/promises API to:
- Read directory contents recursively
- Identify directories named
node_modules - Use
fs.rm()withrecursive: trueandforce: trueto remove them completely - Continue scanning even if some deletions fail due to permissions
While node_modules can always be restored with npm install, be cautious when running this in directories containing important data.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.