Created
September 5, 2020 02:46
-
-
Save joeyguerra/6907f4fd2da3441ef3a84a843b83eae5 to your computer and use it in GitHub Desktop.
Parse a .env file key/value pairs
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
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