no-console-logs
v0.0.1
Published
Hide console.logs on production
Maintainers
Readme
no-console-logs
A lightweight npm package that hijacks console.log to only work on localhost or allowed URLs. Perfect for preventing console logs from appearing in production environments.
Installation
npm install no-console-logsUsage
Import and call enableNoLogs() at the entry point of your application:
import { enableNoLogs } from 'no-console-logs';
enableNoLogs();Or with CommonJS:
const { enableNoLogs } = require('no-console-logs');
enableNoLogs();By default, console.log will only work when running on:
localhost127.0.0.1[::1](IPv6 localhost)
Advanced Usage
You can specify additional allowed hosts:
import { enableNoLogs } from 'no-console-logs';
enableNoLogs(['dev.example.com', 'staging.example.com']);How it works
The package stores the native console.log function in a temporary variable, then overrides it with a custom function that checks the hostname. If the hostname matches localhost or any allowed URLs, it calls the native function with the passed arguments. Otherwise, it ignores the console.log calls.
License
MIT
