Skip to content

Instantly share code, notes, and snippets.

@joeyguerra
Created September 5, 2020 02:46
Show Gist options
  • Save joeyguerra/6907f4fd2da3441ef3a84a843b83eae5 to your computer and use it in GitHub Desktop.
Save joeyguerra/6907f4fd2da3441ef3a84a843b83eae5 to your computer and use it in GitHub Desktop.
Parse a .env file key/value pairs
import assert from "assert"
describe("PropertyFile - externalize configuraiton with environment variables", ()=>{
it("Should parse an env file", async done => {
const env = `
CLIENT_ID="something"
CLIENT_SECRET="something"
# something id
ID=1
`
let config = {}
env.split(/\n/).forEach(line=>{
let kv = line.split("=")
if(kv.length > 1){
config[kv[0].trim()] = kv[1].replace(/^\"/, "").replace(/\"$/, "")
}
})
assert.equal(config.CLIENT_ID, "something")
assert.equal(config.ID, 1)
done()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment