How to use the env file sorter
- Paste the contents of your
.envfile into the .env box. The sample has comments, a duplicateDB_HOSTand a multi-line private key. - Keep Ignore case when sorting ticked for natural A–Z order.
- Tick Blank line between prefix groups (DB_, API_…) to separate variables by their first word.
- Check the Variables count and any duplicate warning, then copy the Sorted .env or download it.
What it does and when to use it
.env files grow by appending: someone adds DB_HOST at the bottom months after the first one was set at the top. Sorting brings related settings together and reveals keys defined twice. Use it before committing a .env.example or when a setting you changed seems to have no effect.
To compare two sorted files, use the code diff viewer. For other config formats, try the Java properties formatter or the INI formatter. To build a new file from JSON, see JSON to .env.
How it works
The sorter reads the file line by line in your browser:
- A line like
NAME=valueorexport NAME=valueis a variable. Names may contain letters, digits,_,.and-. - Lines starting with
#, and any line that is not a variable, are held and attached to the next variable. - If a value opens a quote that does not close on the same line, the following lines are added to that variable until the closing quote.
- Blank lines are dropped, the variables are sorted by name, and each is written with its comments above it, exactly as typed.
Duplicates are found by exact name. With grouping on, a blank line is inserted whenever the part of the name before the first _ or . changes.
Worked examples
These are the tool’s own outputs.
The sample. Seven variables come out in this order: API_KEY, APP_NAME, DB_HOST (twice), DB_USER with # Database above it, PORT with # App above it, and the three-line PRIVATE_KEY. The note reads “Duplicate keys: DB_HOST. Which value wins depends on the loader, so remove the extra one.”
With prefix groups. API_KEY and APP_NAME land in separate groups because their first words differ (API and APP), while both DB_ variables share one.
Case-sensitive order. With Ignore case unticked, API_KEY, export NODE_ENV, api_url and b sort in that order: upper case first, and export does not count.
Limits and tips
- Values are never changed, so quoting or escaping problems in your file remain.
- Duplicates are flagged, not removed.
- Variable expansion such as
${DB_HOST}is not evaluated, and sorting may move a variable above the one it refers to.
Frequently asked questions
Is it safe to paste real secrets here?
Which value wins when a key appears twice?
Why did my section comments move?
Are multi-line values safe?
What does Ignore case when sorting change?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.