Skip to content
BENIBIX Learn

.env File vs Config File

People think a .env file is just one more config file, and it is not. A config file holds settings that are the same for everyone, so it goes into Git with the code. A .env file holds the secrets and values for one machine. It must stay out of Git, and each machine keeps its own copy.

Development📄 Files & Formats

.env File

Secret keys and passwords in a file. It stays out of the code and Git.

A .env file holds secrets as simple lines, like API_KEY=abc123. A program loads them as environment variables when it starts. This keeps passwords and keys out of the code itself. Each machine has its own .env, with its own values. It should always be listed in .gitignore so it is never committed.

Example
Jack keeps his payment key in .env. His laptop uses a test key, and the live server has the real one in its own .env.
Why it matters
Secrets in code end up in Git. Then anyone with the repo can find them.
Full entry
Development📄 Files & Formats

Configuration File

Settings a program reads when it starts. They sit in a file apart from the code.

A configuration file holds the settings a program reads when it starts. It sets things like the port to use, the database to connect to or which features are on. Changing the file changes how the program acts, with no change to its code. Common formats are YAML, JSON, TOML and INI. Most projects have several, one for each tool they use.

Example
Emma's app reads port: 8080 from its config file. To move it to port 3000, she changes one line and restarts it.
Why it matters
With settings out of the code, one program can run in many places. Each place sets it up its own way.
Full entry

In one line

.env File
Secret keys and passwords in a file. It stays out of the code and Git.
Configuration File
Settings a program reads when it starts. They sit in a file apart from the code.