Find and remove unused Next.js API routes & Nest.js Controllers. 🪓
npm install -g pruny
# or
npx pruny| Command | Description |
|---|---|
pruny |
Scan for unused items interactively (monorepo-aware). |
pruny --dir <path> |
Set the target project directory (default: ./). |
pruny --app <name> |
Scan a specific application within a monorepo. |
pruny --folder <path> |
Scan a specific folder OR sub-directory for routes/controllers. |
pruny --fix |
Automatically delete unused items found during scan. |
pruny --cleanup <items> |
Quick cleanup: routes, exports, public, files. (e.g. --cleanup routes,exports) |
pruny --filter <pattern> |
Filter results by string (app name, file path, etc). |
pruny --ignore-apps <list> |
Comma-separated list of apps to skip in monorepos. |
pruny --no-public |
Disable scanning of public assets. |
pruny --json |
Output scan results as JSON for automation. |
pruny -v, --verbose |
Show detailed debug logging and trace info. |
pruny init |
Create a pruny.config.json configuration file. |
Pruny automatically scans your public/ directory for unused images and files.
- Enabled by default: Run
npx prunyand it will show unused assets, excluding ignored folders. - Disable it: Use
--no-publicflag.pruny --no-public
- How it works: It checks if filenames in
public/(e.g.,logo.pngor/images/logo.png) are referenced in your code.
Create pruny.config.json (optional):
{
"dir": "./",
"ignore": {
"routes": ["/api/webhooks/**", "/api/cron/**"],
"folders": ["node_modules", ".next", "dist"],
"files": ["*.test.ts", "*.spec.ts"]
},
"extensions": [".ts", ".tsx", ".js", ".jsx"]
}- 🔍 Detects unused Next.js API routes & Nest.js Controller methods
- 🗑️
--fixflag to delete unused routes - ⚡ Auto-detects
vercel.jsoncron routes - 📁 Default ignores:
node_modules,.next,dist,.git - 🎨 Beautiful CLI output
- Next.js: Finds all
app/api/**/route.tsfiles. - Nest.js: Finds all
*.controller.tsfiles and extracts mapped routes (e.g.,@Get('users')). - Scans codebase for client-side usages (e.g.,
fetch,axios, or string literals matching the route). - Reports routes with no detected references.
--fixdeletes the unused route file or method.
MIT