Last active
March 7, 2024 20:38
-
-
Save idkwebdev/685064327faad43000ebfeb83e87cd29 to your computer and use it in GitHub Desktop.
A quick and easy .env parser for Node.js
This file contains hidden or 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
function parseENV(content) { | |
var contentArray = content.split('\n') | |
var contentDict = {} | |
for (var i = 0; i < contentArray.length; i++) { | |
if (contentArray[i] === '') { continue } | |
contentArray[i].replace('\r', '') | |
contentArray[i].trim() | |
var contentItemSplit = contentArray[i].split('=', 2) | |
contentDict[contentItemSplit[0]] = contentItemSplit[1] | |
} | |
return contentDict | |
} | |
module.exports = { | |
parseENV: parseENV | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment