Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
Example 2 shows how to use the function to replace the browser's default console with our new debug console. In this case, we're using process.env.NODE_ENV to enable logging in non-production builds. (This assumes that your build process replaces process.env.NODE_ENV with the value of the NODE_ENV environment variable.) You could also set the enabled option based on a value from a dotenv file or any other source of configuration.
The JavaScript console is a very useful debugging tool, but it can also introduce a very simple security risk into your application: console method calls that aren't removed before code is deployed can leak sensitive information to the browser. That's why many developers use a linter to warn about console method calls and other issues. (On RedBit's web team, we use husky to run the linter on a pre-commit hook so that console method calls are never committed by accident. We've found that many small bugs can be avoided by making linting mandatory before committing code.)
The console created by createDebugConsole will not be active in unit tests, so you won't be able to use it to prevent logging in your test environment. If you use jest you can silence console methods with the jest CLI.
The JavaScript console is a very useful debugging tool, but it can also introduce a very simple security risk into your application: console method calls that aren't removed before code is deployed can leak sensitive information to the browser. That's why many developers use a linter to warn about console method calls and other issues. (On RedBit's web team, we use husky to run the linter on a pre-commit hook so that console method calls are never committed by accident. We've found that many small bugs can be avoided by making linting mandatory before committing code.)