About .env file generator
A .env file holds configuration for your app, such as database URLs and API keys, outside of the code.
Good practice
- Never commit a real .env to Git. Commit a .env.example with placeholder values.
- Use different values for development and production.
- Rotate any secret that was committed by mistake.
A worked example
From lines such as DATABASE_URL=postgres://... and API_KEY=abc123 you get a clean .env, a .env.example with the values removed, and JSON or Docker flag versions. Commit only the example file, and add .env to .gitignore.
Rules of thumb
- Use upper case names with underscores.
- Quote values that contain spaces or a # sign.
- Keep different files for development, testing and production.
Loading the file
Most frameworks load .env automatically in development. In production, set the variables in your host's settings, rather than shipping the file.
