How to compare .env files

By

Compare a .env file with .env.example in the browser. Find missing keys, extra keys, empty values, and repeated keys before you deploy.

~~~

Free toolThis tutorial uses the .env Diff. It runs in your browser, so open it in another tab and follow along.

To compare .env files, put .env.example on one side and your local .env on the other. Read the keys that are missing, extra, empty, or different before you boot the app.

We’ll use the .env diff tool. Both files stay in the browser. Secrets are not put in the URL.

Compare the sample

  1. Open .env diff.
  2. Click Load sample. The left box is the example. The right box is the local file.
  3. Read the table. Matching keys are hidden until you untick Hide matching keys.
  4. Read the problem list above the table. A repeated key is named there, with the earlier line number.

The example is:

# Keys this app reads
DATABASE_URL=postgres://localhost:5432/notes
SESSION_SECRET=
PORT=3000
LOG_LEVEL=info

The local file sets PORT twice, changes the log level, adds a flag, and leaves the secret empty:

DATABASE_URL=postgres://localhost:5432/notes
PORT=3000
LOG_LEVEL=debug
EXTRA_FLAG=1
SESSION_SECRET=
PORT=3001

The rows are:

KeyStatus.env.example.env
DATABASE_URLmatchpostgres://localhost:5432/notespostgres://localhost:5432/notes
SESSION_SECRETempty
PORTdifferent30003001
LOG_LEVELdifferentinfodebug
EXTRA_FLAGextra1

PORT is different because the comparison uses the last value, 3001. The problem list says:

Line 6: PORT is repeated. The comparison uses this value. The earlier one is on line 2.

SESSION_SECRET is empty on the local side, even though the example is empty too. An empty string is called out on its own, so a forgotten secret does not look like a match.

How .env.example is compared with .envPaste the example and the local file. The tool ignores blank lines and full-line comments, keeps the last value when a key repeats, and labels each example key missing, empty, different, or match. Keys that exist only in the local file are extra.Example onlyLocal onlyBoth, local value emptyBoth, values differBoth, same non-emptyvaluePaste .env.exampleand .envIgnore blanks andfull-line commentsKeep the last valueof a repeated keyIs the key in bothfiles?missingextraemptydifferentmatch

What each status means

StatusMeaning
missingThe key is in the example and not in the local file
extraThe key is only in the local file
emptyThe local value is an empty string
differentBoth sides have a value and the strings differ
matchBoth sides have the same non-empty value

Example keys stay in example order. Extra keys follow, in the order they appear in the local file. The summary counts problems, which are every row that is not match. The table shows the first 400 rows. Each file can be up to 2 MB. Copy and Download follow the hide-matching checkbox.

How a line is read

These are the rules this tool uses. They are listed on the tool page.

Blank lines and full-line # comments are ignored. An optional export prefix is stripped. Spaces around = are ignored. An unquoted value ends at a space and then #, so export DATABASE_URL = postgres://localhost/notes # local only is the key DATABASE_URL and the value postgres://localhost/notes.

Double quotes interpret \\, \", \n, \r, and \t. A missing closer can run onto later lines. Single quotes are literal, so a backslash inside them stays a backslash. $VAR and ${VAR} are not expanded. URL=$HOST:3000 is compared as the string $HOST:3000.

A line without =, an empty key, text after a closing quote, and an unclosed quote are reported above the table. A key that is not letters, digits, and underscores is reported and still compared.

Where this shows up

How to use .env files in Node.js with import syntax loads a file into process.env. How to read environment variables from Node.js is the matching read. The Docker Compose introduction is where an .env.example with empty values belongs in the repo, next to a gitignored .env.

If you need the file as JSON or YAML instead of a comparison, use the .env converter. A database URL you want split into host, port, and database goes to the connection string parser. A docker run line that sets the same variables goes to docker run to Compose.

Try the .env Diff

Compare a .env file with .env.example in your browser. Find missing keys, extra keys, empty values, duplicate keys, and broken quotes.

Open the .env Diff →

  • .env Converter: Convert .env files to JSON or YAML and back, in your browser — comments, quotes, and multiline values handled.
  • Docker Run to Compose Converter: Convert common docker run flags, volumes, ports, and environment variables into Compose YAML.
  • Connection String Builder: Build or parse Postgres, MySQL, and SQLite connection strings. Passwords stay in your browser.

More tool tutorials →

Want me to talk about your product? You can sponsor this site.