Tutorial · .env Validator · 3 min read

.env File Syntax Rules and Common Mistakes

Check a .env file for invalid lines, duplicate keys, unbalanced quotes and naming problems, and learn the quoting rules that differ between dotenv loaders.

There is no formal .env specification, and Node, Python, Ruby, Go and Docker Compose each parse the file a little differently. What they agree on is enough to check: KEY=VALUE per line, keys made of letters, digits and underscores, balanced quotes, and no duplicates, because the last one silently wins.

What you'll learn

  • Write lines every dotenv loader accepts
  • Find duplicate keys before they overwrite each other
  • Quote values with spaces, hashes or special characters correctly

Step by step

  1. Paste the .env contents

    Open the .env File Validator and paste the file. It stays in your browser; treat real secrets with the same care as anywhere else.

  2. Click Validate

    Each finding names the line. Errors are lines a loader will reject or misread; warnings are things that work but surprise.

    DATABASE_URL=postgres://localhost/app
    DATABASE_URL=postgres://prod/app   → WARNING duplicate, last value wins
    bad line here                      → ERROR   not KEY=VALUE
    SECRET_KEY="unterminated           → ERROR   unbalanced quote
    debug=true                         → INFO    keys are usually UPPER_SNAKE_CASE
  3. Fix the file

    Remove duplicates, close quotes, and quote any value that contains spaces or a # so it is not read as a comment.

Open the tool with this example Runs in your browser. Nothing you paste is uploaded.

Common problems

A value with a # got cut off

Unquoted # starts a comment in most loaders. Wrap the value in double quotes.

Variables are not expanding

Expansion of ${OTHER} depends on the loader and on quoting; single quotes usually disable it. Check your library's documentation.

FAQ

Should I commit .env files?

No. Commit a .env.example with placeholder values and keep the real file out of version control.