npkill - Node Modules Cleanup Tool
Overview
npkill is a CLI tool that finds and removes old node_modules directories to free up disk space. It scans your filesystem for node_modules directories and allows you to selectively or automatically delete them.
Quick Start
Scan a directory for node_modules
sc npkill scan directory
Delete all node_modules in a directory
sc npkill delete all --directory ~/projects
Stream results in real-time as JSON
sc npkill stream results --directory ~/projects
Passthrough to npkill CLI
sc npkill _ <npkill-args>
Key Features
- JSON Output: Use
--jsonto output results as a single JSON object, or--json-streamfor real-time JSON output - Automatic Deletion: Use
--delete-allto automatically delete all found node_modules - Selective Deletion: Interactive mode lets you choose which directories to delete
- Size Analysis: Shows the size of each node_modules directory
- Filtering: Exclude specific directories with
--exclude
Installation
npm install -g npkill
Usage Examples
Find node_modules larger than 100MB
npkill --json | jq '.results[] | select(.size > 104857600)'
Automatically delete node_modules in backups
npkill -d ~/backups/ --delete-all
Stream results for monitoring
npkill --json-stream 2>/dev/null | jq -s '.' > clean-results.json
Notes
- npkill is non-interactive when using
--delete-allor JSON output flags - The tool respects
.npkillrcconfiguration files for customization - Use
--excludeto skip specific directories from scanning