# .env Key Sorter

Sort the keys in a .env file alphabetically, keeping each comment with its key and optionally dropping duplicates or aligning values.

- Category: Text (text)
- URL: https://ilham.dev/tools/env-key-sorter/
- Documentation: https://ilham.dev/tools/env-key-sorter/index.md
- Keywords: env, dotenv, environment, variables, config, sort, keys, alphabetical, order, duplicates, align, secrets

## Example questions

- Does it change the values?
- Which duplicate value wins?
- Is my file uploaded?
- Does it understand export?

## Properties

- Runs in the browser
- No login required
- No data uploaded


## About

Put a .env file in alphabetical order without shuffling the comments that belong to each setting. The top comment block stays first, a comment above a key travels with that key, and blank lines are closed up. Duplicate keys can be collapsed to the last value, and the equals signs can be lined up for a tidier read.


## Questions

### Does it change the values?

No. Only whole lines are moved, so spacing, quotes and inline comments inside a value are untouched. Alignment only pads the space before the equals sign.

### Which duplicate value wins?

The last one, which is what most .env loaders use when a key appears twice.

### Is my file uploaded?

No. The file is read, sorted and written in the browser; nothing leaves the page.

### Does it understand export?

Yes. A line like export PORT=3000 is still recognised as the PORT key and keeps its export prefix.

