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

ENV Merger: combine multiple .env files

Merge .env files into one: this ENV merger stacks any number of files as layers, lets later layers override earlier ones, and shows for every key which file it came from and which files it overrode.

By Aliniyaz Mamat · last reviewed

Be the first to rate
later files override earlier ones
#1
#2
NODE_ENV=development
PORT=3000
DATABASE_URL=postgres://localhost/local
DEBUG=true
source of each key
  • NODE_ENV.env.base
  • PORT.env.base
  • DATABASE_URL.env.local (overrides .env.base)
  • DEBUG.env.local

Key takeaways

  • ✓Order matters: put files from lowest to highest priority. The last layer that defines a key wins.
  • ✓An empty value still overrides: JWT_SECRET= in a later layer replaces a real value from an earlier one.
  • ✓The winning line keeps its quotes and inline comment; values with #, spaces or $ are quoted so they survive.
  • ✓Real loaders disagree on order. Next.js and Vite give .env.local priority; dotenv.config({ path: [a, b] }) lets the first file win.

What it does

  • ▸Merge 2 or more .env files as ordered layers
  • ▸Last layer wins, like docker compose env_file lists and node --env-file
  • ▸Per-key source, including which layers were overridden
  • ▸Keeps quotes and inline comments of the winning line
  • ▸Copy or download the result, 100% client-side

Privacy

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

client-side only

Usage examples

Case 1 · Base + local override
# .env
DATABASE_URL=postgres://localhost/dev
PORT=3000
# .env.local
DATABASE_URL=postgres://localhost/mine
DATABASE_URL=postgres://localhost/mine
PORT=3000
Case 2 · Quotes survive the merge
# .env
SMTP_PASS=old
# .env.production
SMTP_PASS="n3w#pass" # rotated
SMTP_PASS="n3w#pass" # rotated

When to use this tool

  • →Seeing the effective config of .env + .env.production + .env.production.local
  • →Building one .env for a Docker image or a CI job from a base file and an environment file
  • →Combining service-specific files in a monorepo
  • →Debugging "why does production use the wrong database URL?"

Common mistakes

  • ⚠Putting the layers in the wrong order: reverse the list and every override flips
  • ⚠Overriding with an empty value by accident, which unsets a working secret
  • ⚠Merging real secrets into a file that then gets committed. The merged .env is as sensitive as its most sensitive layer
  • ⚠Assuming full-line comments are merged: only the winning lines (with their inline comments) are kept. Add section comments afterwards

Which file wins? Load order in real tools

ToolFilesWho wins
Next.js.env, .env.local, .env.[mode], .env.[mode].local.env.[mode].local > .env.local > .env.[mode] > .env; real environment variables beat all
Vitesame namesmode-specific beats generic, .local beats non-local; existing env vars beat all
node --env-file=a --env-file=banythe later file (b)
dotenv config({ path: [a, b] })anythe first file (a), unless override: true
Docker Compose env_file: [a, b]anythe later file (b); environment: beats both

To reproduce a framework in the merger, add the layers from lowest to highest priority. For Next.js production that is .env, .env.production, .env.local, .env.production.local.

Merging on the command line

# later files win: keep the LAST definition of each key
cat .env .env.production .env.production.local \
  | grep -E '^(export )?[A-Za-z_][A-Za-z0-9_]*=' \
  | tac | awk -F= '!seen[$1]++' | tac > .env.merged

This keeps the last definition per key in its original position (tac is tail -r on macOS). After merging, the ENV cleaner removes leftovers and the .env formatter sorts and groups the result.

Checking the merge result

  1. Look at the source list under the output: every key shows its winning file, and yellow notes show what it overrode.
  2. Compare the merged file with what production actually has, using the ENV diff checker.
  3. Check that nothing required is missing with the missing env detector against your .env.example.

Frequently asked questions

Which file takes precedence when two files define the same key?

The later layer in the list. Put files from lowest to highest priority, e.g. .env first and .env.local last.

Does an empty value override a filled one?

Yes. KEY= in a later layer wins, just like it would in Next.js or Compose. Remove the line instead if you want the earlier value to apply.

Are comments preserved?

Inline comments on the winning lines are kept. Full-line comments are not merged, because they cannot be attributed to the final key order reliably.

Why are some values quoted in the output?

Values containing spaces, #, quotes, $ or backslashes are wrapped in double quotes so dotenv parsers read them exactly. Values that were quoted in the input stay quoted.

Are my files uploaded?

No. Everything is merged in your browser.

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