
Stop Using Environment Variables for Configuration (Here's What I Do Instead)
I know this is going to be controversial Environment variables are the default for app configuration. Every tutorial uses them. Every framework expects them. .env files are everywhere. But after managing 77 production services and debugging configuration issues at 2 AM, I've stopped using env vars as my primary config mechanism. Here's why — and what I use instead. The problems with env vars 1. No type safety DATABASE_PORT = 5432 # Is this a string or an integer? ENABLE_CACHE = true # Is this a boolean or the string "true"? MAX_RETRIES = three # This will silently break your app Every env var is a string. Your app has to parse them, and if it does it wrong, you won't know until production. 2. No validation at startup Missing DATABASE_URL ? You'll find out when the first query runs — not when the app starts. I've seen apps run for hours before hitting a code path that needs a missing env var. 3. No documentation # .env.example API_KEY = SECRET = DATABASE_URL = REDIS_URL = STRIPE_KEY = S
Continue reading on Dev.to Webdev
Opens in a new tab




