Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Created June 22, 2022 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjarneo/3e8f899b78db2e1f348346cd5d9cb62e to your computer and use it in GitHub Desktop.
Save bjarneo/3e8f899b78db2e1f348346cd5d9cb62e to your computer and use it in GitHub Desktop.
.env to json (no blank lines)
// Node.js program to demonstrate the
// fs.readFileSync() method
// Include fs module
const fs = require("fs");
// Calling the readFileSync() method
// to read 'input.txt' file
const data = fs.readFileSync("./.env", {
encoding: "utf8",
flag: "r",
});
const entries = {};
data.split("\n").forEach((line) => {
const [key, value] = line.split("=");
entries[key] = value;
});
console.log(JSON.stringify(entries));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment