| Feature | .env- files | YAML / JSON | | ---------------------- | ---------------------- | ------------------------------ | | Simplicity | Key‑value, no nesting | Supports hierarchies & arrays | | Shell compatibility | Directly source -able | Needs parsing | | 12‑Factor compliance | ✅ Yes | ❌ No (often files are checked in) | | Standard tooling | dotenv everywhere | Custom parsers per language | | Type safety | Strings only | Native types (numbers, booleans) |
// Install dotenv-flow: npm install dotenv-flow // It automatically detects NODE_ENV and loads .env, .env-local, or .env-[development/production] require('dotenv-flow').config(); console.log(`Running in $process.env.NODE_ENV mode.`); console.log(`Database Host: $process.env.DB_HOST`); Use code with caution. | Feature |
.env.example DATABASE_URL=postgres://:@:5432/ PORT=3000 NODE_ENV=development API_KEY=changeme console.log(`Running in $process.env.NODE_ENV mode.`)
In Python, you can combine python-dotenv with the standard os library to load conditional files: console.log(`Database Host: $process.env.DB_HOST`)