reactJS disable console.log system wide

In your index.js file you can simply replace console.log method with an empty function that does nothing. In Node or Frontend app, this should be placed in the file where the application starts from.

if (process.env.NODE_ENV === 'production') {
  console.log = () => {}
  console.error = () => {}
  console.debug = () => {}
}

Now throughout the application in production environment console.log() calls will print nothing. For all other environments, the usual console.log will work as expected.


In your index.js file, check if you're running in dev or production mode.
Disable console.log if you're in production mode.

if (process.env.NODE_ENV !== "development")
    console.log = () => {};

Given you are using React, it is likely that you are already using babel as a part of your build process.

You can use this babel plugin to remove all the console.* function invocations in the build phase.


A much safer way is to not use console.log and go with a custom logger implementation that you can turn off when needed.

To get you going with something, you can use the excellent debug npm package that makes it easy to turn off globally or selectively and it works on both nodejs server side and client side.