The .env file is one of the most ubiquitous files in modern development — nearly every project that follows the Twelve-Factor App methodology uses one. But .env files have no formal specification, and subtle syntax issues (missing quotes, stray spaces, duplicate keys) are invisible until they cause a runtime bug. An env file parser online lets you inspect and validate your .env files instantly, with no server upload and no tooling setup.

Parse your .env file now →

What Is a .env File?

A .env file stores environment variables as plain text key-value pairs. The convention was popularized by the dotenv library for Node.js and has since spread to virtually every language ecosystem.

# Application config
APP_NAME=MyApp
APP_ENV=production
APP_PORT=3000

# Database
DATABASE_URL=postgres://user:password@localhost:5432/mydb
DATABASE_POOL_SIZE=10

# API keys
STRIPE_SECRET_KEY=sk_live_...
SENDGRID_API_KEY=SG.xxxxxxxx

Libraries like python-dotenv, godotenv, dotenv-java, and Rails’ built-in dotenv support mean your application reads these values at startup and injects them into process.env (Node.js), os.environ (Python), or equivalent.

.env Syntax Rules

Despite its apparent simplicity, .env has several syntax rules that vary between implementations:

Basic Key-Value

KEY=value

No spaces around =. Keys are conventionally UPPER_SNAKE_CASE, though lowercase is valid.

Quoted Values

Use quotes when values contain spaces, special characters, or you want to preserve leading/trailing whitespace:

APP_DESCRIPTION="My awesome application"
GREETING='Hello, World!'

Single and double quotes are both valid. Double-quoted strings support escape sequences like \n, \t, and \".

Multiline Values

Double-quoted values can span multiple lines:

PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA...
-----END RSA PRIVATE KEY-----"

Comments

Lines starting with # are comments. Inline comments are supported by some implementations:

# This is a comment
PORT=8080  # This inline comment is parsed by some libraries

Variable Interpolation

Some dotenv libraries support variable expansion:

BASE_URL=https://api.example.com
API_ENDPOINT=${BASE_URL}/v1

Export Syntax

The export prefix (for shell compatibility) is supported by most parsers:

export DATABASE_URL=postgres://localhost/mydb

Common .env Syntax Mistakes

These mistakes are invisible in a text editor but cause real runtime failures:

Spaces around the equals sign

# Wrong — most parsers treat "KEY " as the key name
KEY = value

# Correct
KEY=value

Unquoted values with special characters

# Wrong — the # starts a comment, truncating the value
PASSWORD=abc#123

# Correct
PASSWORD="abc#123"

Duplicate keys

DATABASE_URL=postgres://dev-host/mydb
DATABASE_URL=postgres://prod-host/mydb  # silently overwrites the first

Windows-style line endings (CRLF)

.env files created on Windows may have \r\n line endings. Some parsers handle this; others produce key names ending in \r, causing subtle KEY\r !== KEY comparison failures.

Missing quotes on values with equals signs

# Wrong — some parsers stop at the second =
API_KEY=abc=def=ghi

# Correct
API_KEY="abc=def=ghi"

Parsing .env in Code

Node.js (dotenv)

npm install dotenv
require('dotenv').config();

// Now available as process.env.KEY
console.log(process.env.DATABASE_URL);

Or with ES modules:

import 'dotenv/config';
console.log(process.env.DATABASE_URL);

Python (python-dotenv)

pip install python-dotenv
from dotenv import load_dotenv
import os

load_dotenv()  # reads .env from current directory

database_url = os.getenv('DATABASE_URL')

To parse a .env file programmatically without loading into environment:

from dotenv import dotenv_values

config = dotenv_values(".env")
print(config)  # OrderedDict of key-value pairs

Go (godotenv)

go get github.com/joho/godotenv
package main

import (
    "fmt"
    "log"
    "os"

    "github.com/joho/godotenv"
)

func main() {
    err := godotenv.Load()
    if err != nil {
        log.Fatal("Error loading .env file")
    }
    fmt.Println(os.Getenv("DATABASE_URL"))
}

Shell (bash)

# Export all vars from .env into current shell
set -a
source .env
set +a

.env Best Practices

Never commit .env to version control. Add it to .gitignore immediately. Commit a .env.example with placeholder values instead.

# .gitignore
.env
.env.local
.env.production

Use separate files per environment. Many frameworks support .env.development, .env.production, .env.test — each loaded automatically based on NODE_ENV or equivalent.

Validate required variables at startup. Libraries like envalid (Node.js) or pydantic-settings (Python) let you define a schema for your environment variables and fail fast if required values are missing or have wrong types.

// envalid example
import { cleanEnv, str, port, url } from 'envalid';

const env = cleanEnv(process.env, {
  DATABASE_URL: url(),
  APP_PORT: port({ default: 3000 }),
  NODE_ENV: str({ choices: ['development', 'test', 'production'] }),
});

Rotate secrets regularly. .env files often contain API keys and database credentials. Treat them as sensitive material — rotate them periodically, especially after team member offboarding.

Exporting .env to JSON

Converting .env to JSON is useful for:

  • Feeding config into tooling that expects JSON (AWS Lambda, Terraform var-file)
  • Comparing configs across environments
  • Documenting configuration in CI/CD pipelines
from dotenv import dotenv_values
import json

config = dotenv_values(".env")
print(json.dumps(dict(config), indent=2))

Output:

{
  "APP_NAME": "MyApp",
  "APP_ENV": "production",
  "APP_PORT": "3000",
  "DATABASE_URL": "postgres://user:password@localhost:5432/mydb"
}

Note that all values are strings in the JSON output — .env has no type system. Type coercion happens at the application layer.

Online .env File Parser

For quick inspection, debugging, or format conversion without running any code, ZeroTool’s env file parser runs entirely in your browser. Paste your .env content to:

  • Visualize all key-value pairs in a clean table
  • Spot syntax errors with line-level highlighting
  • Detect duplicate keys
  • Export parsed data to JSON

No data is sent to any server — the parsing runs entirely client-side.

Try the env file parser →