# .env File

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

**Field:** Software Development  
**Category:** Files & Formats  
**Also known as:** .env, dotenv, Environment File

## 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.

## 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

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.

## Example code

```ini
DATABASE_URL=postgres://localhost:5432/shop
API_KEY=test_123
```

Two settings, one per line, as name equals value.

## Why it matters

Secrets in code end up in Git. Then anyone with the repo can find them.

## Common mistake

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

## Three principles

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

## Related terms

- [.gitignore](https://learn.benibix.com/term/development/gitignore)
- [Configuration File](https://learn.benibix.com/term/development/config-file)
- [Variable](https://learn.benibix.com/term/development/variable)
- [YAML Ain't Markup Language (YAML)](https://learn.benibix.com/term/development/yaml)

## Told apart from

- [.env File vs Config File](https://learn.benibix.com/compare/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.

## Taught in

- [.env Files and package.json](https://learn.benibix.com/learn/development-formats/env-files-and-package-json): File Formats, 6/11

---

Source: https://learn.benibix.com/term/development/env-file
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
