Less confusing defaults

rumkin

Paul Rumkin

Posted on November 15, 2019

Less confusing defaults

The less confusing (and harmful) defaults for code and configuration are different and opposite. Here it is:

By Default

  1. Run production code.
  2. Use development configuration.

Other should be specified implicitly.

Why?

Development code can skip some checks or allow users to override permissions. Production code is (well should be) free of such dangerous behavior. That's why production code should be run by default.

In the same time development configuration usually specifies test database and API endpoints. And thus such configuration couldn't spent users funds or send a real messages and considered less harmful.

How

Debug/Dev mode

āŒ Wrong:

const DEBUG = process.env.NODE_ENV !== 'production'

āœ… Correct:

const DEBUG = process.env.NODE_ENV === 'development'

Config

āŒ Wrong:

const CFG = process.env.NODE_ENV || 'production'

const config = require(`configs/${CFG}.js`)

āœ… Correct

const CFG = process.env.NODE_ENV || 'development'

const config = require(`configs/${CFG}.js`)
šŸ’– šŸ’Ŗ šŸ™… šŸš©
rumkin
Paul Rumkin

Posted on November 15, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How to master HTTP requests with Axios
programming How to master HTTP requests with Axios

February 6, 2023

Less confusing defaults
programming Less confusing defaults

November 15, 2019