import { config , DotenvParseOutput } from 'dotenv' ; import { injectable } from 'inversify' ; @ injectable ( ) export class Env { private env : DotenvParseOutput ; public load ( ) { const output = config ( ) ; this . env = < DotenvParseOutput > output . parsed ; } public get ( key , optional = false ) { if ( ! this . env ) { this . load ( ) ; } if ( ! process . env [ key ] && ! optional ) { throw new Error ( `Environment variable ${ key } not set` ) ; } return < string > process . env [ key ] ; } }