Removing Console logs from Production

Daniel Arikawe
Mar 18, 2022

When building web applications, there’s almost a certainty you would be using console.log() for a couple of reasons e.g reading data from a remote source, capturing event closures, e.t.c.

For security reasons, you wouldn’t want these captured events or remote data to be accessible to the user on their consoles.

To hide or enclose your console.logs in production, use the following steps:

1. Create a config.js file in the root of your application folder

2. Input this syntax.

if (process.env.NODE_ENV === “production”) console.log = function () {};

What this code syntax does is check the production level of your app. If this level happens to be production it changes all console.log to an empty function.

Hope this helps ✨

--

--