The .env file format
A .env file stores configuration as one KEY=value assignment per line,
loaded into a process’s environment at startup. The format looks trivial, but
quoting, comments and interpolation differ subtly between loaders. This
reference documents the rules and includes a live linter that classifies every
line you paste.
How it works
Each non-blank, non-comment line is split at the first = into a key and a
value. The key should be UPPER_SNAKE_CASE and may not start with a digit:
# a comment line
API_KEY="sk_live_123" # double quotes preserve and can interpolate
SECRET='raw$value' # single quotes are fully literal
DB_URL=$HOST/db # $VAR expands in many loaders
export PORT=3000 # export prefix is stripped by the loader
EMPTY= # assigns an empty string
The linter applies exactly this logic: blank and # lines are ignored, a valid
key/value reports whether the value is quoted, empty or unquoted, and a line
with no = (and not a comment) is flagged as an error.
Tips and notes
- Single-quote any secret containing
$so it is not treated as interpolation. - Behaviour varies across Node dotenv, python-dotenv and docker-compose — test in your loader.
- Never commit a real
.env; ship a.env.examplewith placeholder values instead. - Keep keys UPPER_SNAKE_CASE and avoid spaces around
=for the widest compatibility.