ENV guide
Format Dotenv Files Safely for Node, Docker, and Shell
Dotenv, shell, and Docker Compose all represent environment variables, but their parsers do not treat every character identically. Normalize deliberately and inspect generated output instead of copying syntax blindly between formats.
Quote only with a rule
Simple alphanumeric values can usually remain unquoted. Values containing spaces, comment characters, quotes, or shell-significant characters need a representation the target parser understands.
Smart quoting is a safe default for dotenv output because it quotes values when necessary. A no-quotes formatter should reject unsafe values rather than change their meaning silently.
PORT=3000 APP_NAME="Example Service" MESSAGE="contains # text"
Do not confuse dotenv with shell
A dotenv file is parsed as data by a library. A shell export file is executed by a shell and therefore has different escaping and expansion rules. Convert to explicit export statements when a script needs shell syntax.
Docker Compose can embed literal values or reference variables from the host environment. Choose reference mode when the Compose file should remain shareable without containing the values.
# Shell
export PORT=3000
# Docker Compose reference
environment:
PORT: ${PORT}Make diffs boring
A stable order and one assignment per key make configuration reviews easier. Sort keys when order has no semantic meaning, keep comments only when their relationship remains clear, and collapse duplicates after confirming which value should win.
- Format a copy and review the diff before replacing the source.
- Keep secrets out of formatter logs and online tools that upload content.
- Validate after conversion because the target format may have stricter rules.
Apply the guide privately
EnvSift processes ENV content locally in your browser and does not send keys or values to a server.
Format a dotenv file