What Belongs in a .env.example File (and What Doesn't)
A .env.example file tells a new developer which environment variables the project needs. Done well, it saves an afternoon. Done badly, it becomes the second place secrets leak from.
The rule is simple: the file lists the names of your variables and safe placeholder values. It never contains a real credential.
What a good .env.example looks like
# Database
DATABASE_URL=postgres://user:password@localhost:5432/app_dev
# Auth
SESSION_SECRET=change-me-locally
# Third-party
STRIPE_SECRET_KEY=sk_test_replace_me
Each line does three things:
- Names the variable so a new engineer knows it exists
- Shows the expected format, such as the shape of a connection string
- Uses a placeholder that cannot grant access to anything
Add a short comment above each group when the purpose is not obvious. Comments are cheap and they age well.
What does not belong in it
- Real passwords, even old or "dev-only" ones
- Production hostnames or internal IP addresses
- Live API keys, including test keys tied to a real account
- Values that differ per developer and would be wrong for anyone else
If a real value is in git history, treat it as exposed. Rotate it and remove it from history. Our guide on removing a .env file from Git history covers the cleanup steps.
Keep the file in sync
A .env.example drifts the moment someone adds a variable and forgets to update it. Two habits prevent most of the drift:
- Update the example in the same pull request that introduces the variable.
- Have the app fail fast on startup when a required variable is missing. The error message will point a new developer to the right name.
Where the real values live
Developers still need real values to run the app. Those should come from a shared, encrypted source, not from a file passed around in chat. Pull them per project and environment, and keep local copies out of version control by listing .env in .gitignore.
A new engineer should be able to go from clone to running app in a few commands: copy the example, fill in the values their role allows, and start the service. Nothing in the repo should need a secret to get there.
