All Tools View Categories About Contact Privacy

Env File Sorter

Sort .env keys alphabetically or group them by prefix, keeping comments with their keys.

Runs entirely in your browser — nothing is uploaded.

About Env File Sorter

A tidy .env is one you can scan. The Env File Sorter orders keys alphabetically — ascending or descending — or groups them by prefix so DB_, API_, and PUBLIC_ variables sit together.

Comments that document a key travel with it, so reordering never orphans an explanation. The result is deterministic: run it twice and the file comes out identical.

Features

  • Two orders: A-Z and Z-A.
  • Prefix grouping: section by first underscore segment.
  • Comments travel: headers stay with keys.
  • Deterministic: stable sort, repeatable output.
  • Copy or download: ready to save.
  • Private: fully client-side.

How to Use

  1. Paste your .env or load the sample.
  2. Pick a sort order and optional grouping.
  3. Click Sort. The reordered file appears.
  4. Copy it back into your project.

Examples

Example 1 — Onboarding. New contributors scan a sorted file quickly instead of hunting for a key.

Example 2 — Review diffs. Sorting before a commit gives reviewers a stable diff instead of a shuffled file.

Example 3 — Merging services. Grouping by prefix makes combined configs readable again.

Example 4 — Convention. A repo adopts alphabetical order; the sorter enforces it on every file.

Benefits

  • Scannable: find keys at a glance.
  • Stable diffs: deterministic ordering.
  • Grouped views: prefix sections.
  • Comment-safe: docs stay attached.
  • Private: nothing uploaded.

Frequently Asked Questions

What does this tool do?
Sorts the KEY=value lines of a .env file alphabetically (A-Z or Z-A) or sections them by prefix (everything before the first underscore).
What happens to comments?
Comments and blank lines that sit above a key travel with that key, so documentation stays attached while the file is reordered.
How does prefix grouping work?
Each key is placed in the group of its first underscore segment (DB_HOST and DB_PORT both join DB). Groups are sorted alphabetically, then keys inside each group.
Is anything uploaded?
No. Sorting is a client-side operation on the text you paste.