What is a .env file?
An environment file stores configuration as simple pairs of a key and a value that your application reads at start-up. It keeps database URLs, API keys and feature flags out of source code, so the same build runs in development, staging and production with different values.
The format
- One pair per line: KEY=value
- No spaces around the equals sign
- Quote values that contain spaces
- Lines starting with a hash are comments
Common keys by framework
| Stack | Typical keys |
|---|---|
| Node / Express | PORT, DATABASE_URL, JWT_SECRET |
| Next.js | NEXT_PUBLIC_API_URL, NEXTAUTH_SECRET |
| Django | SECRET_KEY, DEBUG, ALLOWED_HOSTS |
| Rails | DATABASE_URL, RAILS_MASTER_KEY |
The .env File Generator builds a starter file for each of these so you do not have to remember every variable name.
Never commit it
Your .env holds secrets, so it must never reach version control. Add .env to .gitignore - the .gitignore Generator includes the right rules by default - and commit a .env.example with placeholder values so teammates know which keys to set.
Production is different
On a server, set variables through the host's dashboard or your deployment tool rather than shipping a file. Environment files are a local-development convenience, not a secure secret manager. For anything sensitive at scale, use a dedicated secrets service.
Common mistakes
- Trailing spaces after a value, which some parsers keep.
- Committing the real file instead of an example.
- Reusing development secrets in production.
- Forgetting to load the file before it is read.
Get these right and configuration stops being a source of surprises and leaked keys.