Validate Dotenv Syntax and Duplicate Keys
Admin ·
When repeated variables or a broken assignment cause a deployment problem, start with the text of the .env file and compare the line numbers. A syntax check can also tell you which apparent errors are ordinary dotenv constructs, such as an empty string or a quoted line break.
Find three issues in the example
Select Load example, then Validate .env. The checker reports three issues. Line 6 repeats PORT, which first appears on line 2. Line 7 is missing the equals sign. Line 8 has a hyphen in BAD-KEY, which is outside the documented variable name grammar.
EMPTY= on line 3 is valid. The double-quoted MESSAGE starts on line 4 and closes on line 5. Its hash is part of the value, while PORT still appears on physical line 6.
Node.js dotenv names, values and commentsNode.js util.parseEnv API
Repair the assignments and validate again
Keep the PORT assignment your environment expects and delete the other one. Change MISSING_EQUALS to MISSING_EQUALS= and BAD-KEY=value to BAD_KEY=value. Validate again. The report shows five assignments and no issues.
If your file contains Git conflict markers, use the .env Merge Conflict Resolver before checking it again. Unresolved markers indicate that you still need to choose lines from competing versions.
Node.js dotenv names, values and commentsGit merge conflict markers
Verify the settings your application actually reads
A clean result establishes that the file follows the checker’s Node.js dotenv syntax and gives one assignment per name. An acceptable PORT or a required API key is an application question. Read the application’s configuration schema and verify it loads the intended file.
Some runtime loaders continue after malformed lines or accept later assignments to the same name. Fix the reported syntax and duplicates so the saved file has one clear interpretation when handed off.
Node.js dotenv names, values and commentsNode.js util.parseEnv API
Common questions
Is a copy of my settings included in the diagnostics?
The report shows issue descriptions, line numbers and the first assignment’s line for a duplicate. Values stay in the source editor.
Does the checker expand variables or run a shell?
It reads the input as dotenv assignments and keeps substitution expressions as text. It never executes the file.