dotenv Formatter & Validator
Format, sort, and validate environment variable (.env) files.
Client-Side Execution & Privacy Guarantee
This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.
Environment files are simple yet easy to break. A missing equals sign, an unquoted value containing spaces, or a duplicated key can cause an application to start with the wrong configuration. CodePackr's dotenv Formatter & Validator cleans and checks these files locally.
The tool parses each line according to common dotenv rules, reports problems, optionally sorts keys alphabetically, and rewrites the file with consistent formatting. Because everything runs in the browser, secret values never leave your machine.
Valid line formats
A typical line is KEY=value. Keys should consist of letters, digits, and underscores and usually start with a letter. Values may be unquoted, single-quoted, or double-quoted. Empty values are allowed.
Lines that begin with # are comments and are preserved. Blank lines are kept or collapsed according to the formatting option you choose. Export prefixes (export KEY=value) are recognized and can be normalized.
Validation checks performed
Duplicate keys are flagged because most loaders use the last occurrence, which is often unintentional. Lines that lack an equals sign or contain invalid characters in the key are reported with their line numbers.
Unmatched quotes and values that contain unescaped newlines are errors. The validator also warns about keys that differ only by case if your target environment treats them as distinct.
Formatting and sorting options
Formatting rewrites every assignment with a single space around the equals sign or with no spaces, according to your preference, and normalizes quote style. Sorting places keys in alphabetical order while leaving comments attached to the following key or in a header block.
After formatting you can copy the result directly into a .env file. Re-validate to confirm that no new issues were introduced.
When to use this tool
- A .env file has grown messy with inconsistent spacing and you want a clean, sorted version.
- An application fails to read an expected variable and you suspect a duplicate or malformed line.
- You are about to commit a .env.example and want to guarantee it contains no syntax errors.
- You need to compare two environment files structurally after removing secret values.
- You are onboarding a new service and want to standardize the format of its environment template.
How to use the dotenv Formatter & Validator
- Paste the contents of your .env file into the input area.
- Review the list of validation messages, if any.
- Choose whether to sort keys and which quote and spacing style to apply.
- Generate the formatted output.
- Copy the result and replace the original file, or save it as a new template.
- Re-validate the formatted text to confirm it is clean.
- Never paste production secrets into shared or logged environments; the tool itself does not transmit them.
Worked examples
Unsorted file with inconsistent spacing
Z_KEY=last A_KEY = first # comment M_KEY="mid"
Formatted and sorted: # comment A_KEY=first M_KEY=mid Z_KEY=last
Keys are sorted alphabetically, spacing around equals is normalized, and the comment is preserved.
Duplicate key detection
PORT=3000 HOST=localhost PORT=8080
Warning: duplicate key PORT on line 3 (previous definition on line 1). Last value wins in most loaders.
The validator reports the duplicate so you can decide which value to keep.
Common mistakes and tips
- Quote values that contain spaces, hashes, or leading/trailing whitespace.
- Avoid exporting the same key twice; the last definition silently overrides earlier ones in most tools.
- Keep comments on their own lines; inline comments are not universally supported.
- After sorting, review the file once more because related keys may no longer be adjacent.
- Use a .env.example with placeholder values for version control and keep the real .env out of the repository.
Frequently asked questions
Are comments preserved?
Yes. Full-line comments are kept. Their position relative to keys may change if you enable sorting.
How are duplicate keys handled?
They are reported. The formatter keeps the last occurrence, matching the behavior of most dotenv loaders.
Does it support multiline values?
Quoted multiline values are accepted if the quotes are properly closed. Unclosed quotes are flagged as errors.
Can I choose the sort order?
Alphabetical sorting is available. You can also leave the original order and only normalize formatting.
Is the file uploaded?
No. Parsing, validation, and formatting occur entirely in your browser.