Developers constantly google where to store API keys and why .env leaked on GitHub. This is a short, practical checklist.
1. Separate config from code
Use environment variables for anything that changes between dev/staging/prod (DB URLs, API keys, feature flags). Keep a committed .env.example with dummy values only.
2. Never commit secrets
Add .env to .gitignore. If you already committed a key, rotate the credential — git history keeps old blobs.
3. Frontend builds expose embedded secrets
Anything bundled into a browser app (Vite, CRA, Next public env) is visible to users. Use a backend proxy for third-party API keys.
4. Use a secret manager in production
Examples: cloud provider secret stores, Vault, Doppler, 1Password for teams — inject at deploy/runtime, not baked into images when avoidable.
5. Principle of least privilege
DB users should not be superuser. API tokens should be scoped (read-only when possible).
6. Rotation & auditing
Document owners and rotation. Enable audit logs on production config stores. Alert on anomalous API usage.