Created
September 20, 2019 22:12
-
-
Save saltyJeff/c27d2645b51c312abb58993e64af782d to your computer and use it in GitHub Desktop.
static type dotenv
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
class EnvVars { | |
static = 'true' | |
loglevel = 'debug' | |
GOOGLE_APPLICATION_CREDENTIALS = './credentials.json' | |
GOOGLE_CLIENT_ID: string = 'not a valid id' | |
} | |
let cached = false | |
export function env(): EnvVars { | |
if(!cached) { | |
const defaults = new EnvVars() | |
for(const [prop, defaultVal] of Object.entries(defaults)) { | |
if(process.env[prop] === undefined) { | |
process.env[prop] = defaultVal | |
} | |
} | |
cached = true | |
} | |
return process.env as any as EnvVars | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment