Skip to content

Instantly share code, notes, and snippets.

@idkwebdev
Last active March 7, 2024 20:38
Show Gist options
  • Save idkwebdev/685064327faad43000ebfeb83e87cd29 to your computer and use it in GitHub Desktop.
Save idkwebdev/685064327faad43000ebfeb83e87cd29 to your computer and use it in GitHub Desktop.
A quick and easy .env parser for Node.js
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