Created
June 22, 2022 11:18
-
-
Save bjarneo/3e8f899b78db2e1f348346cd5d9cb62e to your computer and use it in GitHub Desktop.
.env to json (no blank lines)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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