Starting points for your own code. Run them in the environment shown below.
Node.js 22+ · ES module (.mjs)
Current inputs apply only to fields used by the example. Selected files are not embedded.
Install dependencies
const text = "APP_NAME=demo\nPORT=8080\n# comment";
const values = Object.create(null);
for (const line of text.split(/\r?\n/)) {
if (!line.trim() || line.trimStart().startsWith("#")) continue;
const match = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(line.trim());
if (!match) throw new Error("Expected KEY=value");
values[match[1]] = match[2]; // Values stay strings.
}
console.log(JSON.stringify(values, null, 2));
// Basic unquoted, single-line format only; no expansion or shell execution.
Put it to work
Convert .env documents and JSON objects.
Details that matter
Format and meaning
Values remain strings, with no variable expansion. The last duplicate key wins. Represent multiline values as \n inside double quotes.
Supported scope and limits
Text 1 MB
Split inputs that exceed the limit. If a format or algorithm is unsupported, choose a tool that matches your requirements instead of silently changing the format.