bene : studio is a global consultancy, helping startups, enterprises and HealthTech companies to have better product

Remove console.log() Statements from Production JavaScript Apps

console-log

Pardon the interruption, we have an important message!

We are looking to expand our team with talented developers. Check out our open positions and apply.

At bene : studio we love knowledge sharing to help the community of professionals. With 10+ years and over 100 projects behind us, we have a vast amount of experience. This is why we have launched a knowledge base on our blog with regular updates of tutorials, best practices, and open source solutions.

These materials come from our internal workshops with our team of developers and engineers.

console.log() statements in JavaScript code to be removed in production

This post presumes that you use modern JavaScript with Babel transpiler.

The Good Parts

console.log() statements are really handy tools for JavaScript development. We can easily track our app’s execution and peek its states.

The Bad Parts

They can cause serious performance issues in applications especially when accidentally left in render logics. It is also risky to log sensitive data on the console in production such as passwords, keys, etc.

Solution

Install babel plugin

npm install babel-plugin-transform-remove-console --save

Edit .babelrc file

{
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}

You are done

console.log() statements no longer exist in your transpiled codebase therefore do not cause performance issues nor flood the console in production.

Read more

React Native docs: https://facebook.github.io/react-native/docs/performance.html#using-consolelog-statements

Did you like this? Join us!

Want to ask some questions? Share them with us via e-mail to partner@benestudio.co and we can set up a talk with our engineers.

Fancy working for the studio where you can work on international projects and write articles like this? Check out our open positions!

Looking for a partner for your next project? Check out our services page to see what we do and let’s set up a free consultation.

console-log

Let bene : studio enhance
your digital product!