.env

What is a .env file?

Environment Variables File · Code and data · Community convention (dotenv) · 2012

A .env file stores configuration as simple KEY=value lines, used to keep secrets and settings (API keys, database URLs) out of source code. It is loaded into a program's environment at startup.

Category
Code and data
MIME type
Type
Plain text
Is a .env file safe to open? Handle with care. A .env file is plain text and does not execute, but it usually contains secrets. Never commit one to a public repository or share it.

What is a .env file used for?

The .env convention, popularised by the dotenv libraries, lets each developer or deployment set its own values without changing code. Each line is NAME=value; the file is plain text and opens in any editor.

Because .env files hold secrets, they are almost always excluded from version control via .gitignore. Committing one by accident is a common way credentials leak.

How to open a .env file

The .env format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .env file.

Windows

  • VS Code
  • Notepad++
  • any text editor

macOS

  • VS Code
  • TextEdit
  • any text editor

Linux

  • VS Code
  • nano
  • any text editor

.env file signature (magic bytes)

Programs recognise a .env file by the bytes at the start of the file, not by its name. These are the signatures for ENV.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

Frequently asked questions

What is a .env file?

A .env file stores configuration as simple KEY=value lines, used to keep secrets and settings (API keys, database URLs) out of source code. It is loaded into a program's environment at startup.

How do I open a .env file?

Any text editor opens it. In some file managers you may need to show hidden files, since names beginning with a dot are hidden by default.

Why is my .env file not being read?

The app must load it (many use a dotenv library), the file must sit where the app looks, and each line must be NAME=value with no spaces around the equals sign.

Should I commit my .env file to Git?

No. It holds secrets. Add .env to .gitignore and share a .env.example with blank values instead.

Related formats

Sources

Details on this page were checked against authoritative references: