npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

console-log-remove

v0.0.1

Published

Find and remove console.log statements - interactive or automatic

Readme

console-log-remove

Find and remove console.log statements from your code - safely and quickly

npm version License: MIT

Problem

You have 500 console.log() scattered everywhere. Production deploy is in 10 minutes.

Solution

console-log-remove finds and removes console statements safely, with options to keep error/warn and create backups.

Features

  • 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

Installation

# Run directly with npx (recommended)
npx console-log-remove

# Or install globally
npm install -g console-log-remove

# Short alias
npx clr

Usage

Preview (Dry Run)

# See what would be removed without making changes
npx console-log-remove --dry-run

# Preview in a specific directory
npx console-log-remove ./src --dry-run

Remove All

# Remove all console statements
npx console-log-remove --remove-all

# Keep console.error and console.warn
npx console-log-remove --remove-all --keep-error --keep-warn

# Or use --keep flag
npx console-log-remove --remove-all --keep error,warn,info

Statistics Only

# Just show stats, don't remove anything
npx console-log-remove --stats

Example Output

Scan Results

🔍 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

Dry Run

🔍 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.

After Removal

✓ 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 <methods>        Comma-separated methods to keep (e.g., error,warn)
  --no-backup             Do not create backup files
  --include <patterns>    Glob patterns to include (comma-separated)
  --exclude <patterns>    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.profileEnd

Programmatic Usage

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

# 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:

# Restore a single file
mv src/utils/api.ts.backup src/utils/api.ts

# Restore all backups
find . -name "*.backup" -exec sh -c 'mv "$1" "${1%.backup}"' _ {} \;

# Remove all backups (after verifying changes)
find . -name "*.backup" -delete

Requirements

  • Node.js 18.0.0 or higher

Support

This project is maintained in my free time. If it saved you from embarrassing console.logs in production, I'd really appreciate your support:

Thank you to everyone who has contributed, shared feedback, or helped spread the word!

License

MIT


Made with ❤️ for cleaner production code