.env · transform🔒 100% client-side — never leaves your browser

ENV Formatter: sort, align and tidy .env files

Format a .env file online: the ENV formatter sorts keys, aligns the = signs, removes duplicates and groups keys by prefix, while values, quotes, export and the comments above each key stay exactly as they were.

By Aliniyaz Mamat · last reviewed

Be the first to rate
api_key   =def
DB_URL    =postgres://...
NAME      =has space
PORT      =3000
STRIPE_KEY=sk_test_xxx

Key takeaways

  • ✓Comment lines directly above a key move with that key when you sort or group, so # from Stripe dashboard stays next to STRIPE_SECRET_KEY.
  • ✓Values and quotes are never rewritten: "a\nb" keeps its double quotes, because dotenv only turns \n into a line break inside them.
  • ✓UPPER is off by default. Renaming apiKey to APIKEY would break code that reads process.env.apiKey.
  • ✓dedupe keeps the last definition of a key, which is the one dotenv loads.
  • ✓Lines that are not valid KEY=value are dropped. Check them first with the .env validator.

What it does

  • ▸Sort keys alphabetically
  • ▸Align = signs into one column
  • ▸Group keys by prefix (DB_, STRIPE_, NEXT_) under a heading
  • ▸Remove duplicate keys, keeping the last definition
  • ▸Keeps values, quotes, export and attached comments. 100% client-side

Privacy

Runs 100% in your browser. Your .env never touches our servers.

client-side only

Usage examples

Case 1 · Sort + align, comments travel along
# Stripe dashboard > API keys
STRIPE_SECRET_KEY=sk_test_123
APP_PORT=3000
DATABASE_URL=postgres://db/app
APP_PORT         =3000
DATABASE_URL     =postgres://db/app

# Stripe dashboard > API keys
STRIPE_SECRET_KEY=sk_test_123
Case 2 · Group by prefix
DB_HOST=localhost
STRIPE_KEY=sk_test_1
DB_PORT=5432
# DB
DB_HOST=localhost
DB_PORT=5432

# STRIPE
STRIPE_KEY=sk_test_1
Case 3 · Quotes and export are kept
export APP_NAME="My App"
PRIVATE_KEY="line1\nline2"
TOKEN='abc$def'
export APP_NAME="My App"
PRIVATE_KEY="line1\nline2"
TOKEN='abc$def'

When to use this tool

  • →Making a long .env readable before a code review of .env.example
  • →Getting a stable key order so diffs between environments are small
  • →Grouping 40+ keys by service (DB_, REDIS_, STRIPE_, SENTRY_)
  • →Normalising files from different developers to one style

Common mistakes

  • ⚠Switching on UPPER for a project that reads mixed-case names: the keys change, the app no longer finds them
  • ⚠Using align = for files read by docker run --env-file: Docker rejects a variable name that contains spaces. Keep alignment for dotenv-based apps
  • ⚠Expecting comments in between keys (not directly above one) to stay put. A comment followed by a blank line is a free-floating note and is dropped
  • ⚠Formatting instead of fixing: invalid lines disappear from the output. Validate first

A .env style guide that works in every language

Dotenv parsers in Node.js, Python, Ruby, Go and PHP agree on a small common core. Stick to it and the same file works everywhere:

  • Key names: UPPER_SNAKE_CASE, letters, digits and underscores, not starting with a digit.
  • No spaces around `=` in files used by Docker or shell scripts; KEY=value, not KEY = value.
  • Quote values that contain spaces, # or line-break escapes. Use single quotes when a $ must stay literal (dotenv-expand and Compose do not expand inside single quotes).
  • One key per line, comments on their own line above the key.
  • Group by service with a comment heading, and keep the same order in .env.example.
.env
# ── Database ──────────────────────
DATABASE_URL=postgres://app:app@localhost:5432/app
DATABASE_POOL_SIZE=10

# ── Stripe ────────────────────────
# Dashboard > Developers > API keys (test mode)
STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx

# ── App ───────────────────────────
APP_NAME="Acme Billing"
LOG_LEVEL=info

What each option does

OptionEffectChanges what the app reads?
sortkeys A→Z, comments move with their keyno
align =pads key names so = lines upno for dotenv; yes for docker --env-file
dedupekeeps the last definition of each keyno (dotenv already uses the last one)
group by prefixgroups by the part before the first _, adds # PREFIX headingsno
UPPERuppercases key namesyes, only use it if your code reads uppercase names

For pure cleanup without reordering, use the ENV cleaner. To compare the formatted file with another environment, paste both into the ENV diff checker.

Enforcing the format in CI

The open-source dotenv-linter (written in Rust) checks key order, duplicates, spacing and quotes in a pipeline. A minimal GitHub Actions step:

- name: Lint .env.example
  run: |
    curl -sSfL https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s
    ./bin/dotenv-linter .env.example

Lint the committed .env.example, not the real .env, which should never be in the repository. See the guide .env best practices for the rest of the conventions.

Frequently asked questions

Does formatting change my values?

No. Values are copied with their original quotes. Only key order, spacing before =, duplicates and (if you turn it on) key casing change.

Are comments kept?

Comment lines directly above a key are kept and move with it. A comment separated from the next key by a blank line is treated as a loose note and is not included in the formatted output.

Is the aligned output still valid?

For dotenv in Node.js, Python, Ruby and Go, yes: they ignore spaces around =. docker run --env-file rejects names with trailing spaces, so leave align = off for files Docker reads.

How does group by prefix decide the groups?

It takes the part of the key before the first underscore: DB_HOST and DB_PORT go to # DB. Keys without an underscore go to # OTHER.

Why is UPPER off by default?

Environment variable names are case-sensitive on Linux and macOS. Uppercasing apiKey creates a different variable, so it is only safe when your code already reads the uppercase name.

Related tools

Learn more

coming soon

Get notified when env syncing launches

We're building a tiny tool to keep .env files in sync across teammates and environments. Leave your email — no spam, just a single launch ping.

We use your address only for this launch email. You can ask us to delete it at any time. Privacy policy