DEV Community

Paul Rumkin
Paul Rumkin

Posted on

2 1

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`)

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️