Skip to content
BENIBIX Learn

.env File

Development📄 Files & FormatsConfig Files

Also known as .env, dotenv, Environment File

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

Think of it like

Think of it like a locked note of house keys. Your app reads it, but you never show it to anyone.

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.

Definition

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 code

ini
DATABASE_URL=postgres://localhost:5432/shop
API_KEY=test_123
Two settings, one per line, as name equals value.

Common mistake

Committing the .env file. Once a key is in history, treat it as leaked and replace it.

Key takeaways

  1. 1
    Name equals value. One setting per line.
  2. 2
    Secrets stay out. Keys never sit in the code.
  3. 3
    Never committed. Always list it in .gitignore.

Compare

Learn it properly