Skip to content

Instantly share code, notes, and snippets.

@saltyJeff
Created September 20, 2019 22:12
Show Gist options
  • Save saltyJeff/c27d2645b51c312abb58993e64af782d to your computer and use it in GitHub Desktop.
Save saltyJeff/c27d2645b51c312abb58993e64af782d to your computer and use it in GitHub Desktop.
static type dotenv
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