A tidy .env: conventions that save time
Environment files tend to grow without a plan. A few conventions keep them readable.
Naming
Use one prefix per service, upper case and underscores: APP_DB_HOST, APP_DB_PORT. Avoid abbreviations nobody remembers six months later.
Defaults and examples
Commit an example file with safe placeholder values and keep real values out of the repository. Fail fast at startup when a required key is missing instead of falling back silently.
Documentation
# .env.example APP_DB_HOST=localhost APP_DB_PORT=5432 # APP_CACHE_TTL=300 # seconds, optional
Comments next to every optional key answer most questions before they are asked.