Find and remove console.log statements - interactive or automatic
npm install console-log-remove> Find and remove console.log statements from your code - safely and quickly


You have 500 console.log() scattered everywhere. Production deploy is in 10 minutes.
console-log-remove finds and removes console statements safely, with options to keep error/warn and create backups.
- Find all console statements - Scans your entire codebase
- Keep what matters - Keep console.error and console.warn with flags
- Dry run mode - Preview changes before applying
- Automatic backups - Never lose code accidentally
- TypeScript + JavaScript - Works with .ts, .tsx, .js, .jsx, .mjs, .cjs
- Smart removal - Handles multi-line statements and removes empty lines
- Fast - Uses fast-glob for quick scanning
``bashRun directly with npx (recommended)
npx console-log-remove
Usage
$3
`bash
See what would be removed without making changes
npx console-log-remove --dry-runPreview in a specific directory
npx console-log-remove ./src --dry-run
`$3
`bash
Remove all console statements
npx console-log-remove --remove-allKeep console.error and console.warn
npx console-log-remove --remove-all --keep-error --keep-warnOr use --keep flag
npx console-log-remove --remove-all --keep error,warn,info
`$3
`bash
Just show stats, don't remove anything
npx console-log-remove --stats
`Example Output
$3
`
π Found 47 console statements:By type:
console.log: 35
console.error: 8
console.warn: 4
π src/utils/api.ts
L23: console.log('API response:', data)
L45: console.error('Error:', err)
L67: console.log('Request:', config)
π src/components/Login.tsx
L12: console.log('User:', user)
L34: console.warn('Deprecated prop used')
Options:
--remove-all Remove all console statements
--keep-error Keep console.error
--keep-warn Keep console.warn
--dry-run Preview without changes
Example:
npx console-log-remove --remove-all --keep-error --keep-warn
`$3
`
π Dry Run - No files will be modifiedπ src/utils/api.ts
L23: console.log('API response:', data) [REMOVE]
L45: console.error('Error:', err) [KEEP]
π src/components/Login.tsx
L12: console.log('User:', user) [REMOVE]
L34: console.warn('Deprecated prop used') [KEEP]
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Summary:
Would remove: 35
Would keep: 12
Run without --dry-run to apply changes.
`$3
`
β src/utils/api.ts
Removed: 2, Kept: 1
Backup: src/utils/api.ts.backupβ src/components/Login.tsx
Removed: 1, Kept: 1
Backup: src/components/Login.tsx.backup
β
Removed 35 console statements.
Kept 12 statements (error/warn or skipped).
`Comparison with Alternatives
| Feature | console-log-remove | ESLint no-console | babel-plugin | Manual |
|---------|-------------------|-------------------|--------------|--------|
| Find statements | β
| β
| β | β |
| Selective removal | β
| β οΈ (config) | β | β
|
| Keep error/warn | β
| β οΈ (config) | β οΈ | β
|
| Preview changes | β
| β | β | β |
| Automatic backup | β
| β | β | β |
| Statistics | β
| β | β | β |
| Multi-line support | β
| β
| β
| β οΈ |
| No config needed | β
| β | β | β
|
CLI Options
`
Usage: console-log-remove [options] [path]Arguments:
path Directory to scan (default: ".")
Options:
--dry-run Preview changes without modifying files
--remove-all Remove all console statements
--keep-error Keep console.error statements
--keep-warn Keep console.warn statements
--keep Comma-separated methods to keep (e.g., error,warn)
--no-backup Do not create backup files
--include Glob patterns to include (comma-separated)
--exclude Glob patterns to exclude (comma-separated)
--json Output results as JSON
--stats Show statistics only
-V, --version Output version number
-h, --help Display help
`Supported Console Methods
All console methods are detected:
-
console.log, console.debug, console.info
- console.warn, console.error
- console.trace, console.table, console.dir
- console.time, console.timeEnd, console.timeLog
- console.group, console.groupEnd, console.groupCollapsed
- console.count, console.countReset
- console.assert, console.clear
- console.profile, console.profileEndProgrammatic Usage
`typescript
import { scanDirectory, removeFromFile, filterStatements } from 'console-log-remove';// Scan a directory
const result = await scanDirectory('./src');
console.log(
Found ${result.totalStatements} console statements);// Remove from specific file
for (const fileResult of result.files) {
// Keep error and warn
const toRemove = filterStatements(fileResult.statements, ['error', 'warn']);
if (toRemove.length > 0) {
removeFromFile(fileResult, toRemove, true); // true = create backup
}
}
`CI/CD Integration
`yaml
GitHub Actions - fail if console.log found
- name: Check for console statements
run: |
npx console-log-remove --stats --json > console-check.json
COUNT=$(cat console-check.json | jq '.byMethod.log // 0')
if [ "$COUNT" -gt 0 ]; then
echo "Found $COUNT console.log statements!"
exit 1
fi
`Restore from Backup
Backups are created with
.backup extension:`bash
Restore a single file
mv src/utils/api.ts.backup src/utils/api.tsRestore all backups
find . -name "*.backup" -exec sh -c 'mv "$1" "${1%.backup}"' _ {} \;Remove all backups (after verifying changes)
find . -name "*.backup" -delete
``- Node.js 18.0.0 or higher
This project is maintained in my free time. If it saved you from embarrassing console.logs in production, I'd really appreciate your support:
- β Star the repoβit helps others discover this tool
- π’ Share with your team or on social media
- π Report bugs or suggest features
- β Buy me a coffee if you'd like to support development
Thank you to everyone who has contributed, shared feedback, or helped spread the word!
MIT
---
Made with β€οΈ for cleaner production code