Skip to content

Instantly share code, notes, and snippets.

@joewright
Last active April 9, 2025 13:50
Show Gist options
  • Save joewright/e7bb33901bb912448d120c2b8c6425fc to your computer and use it in GitHub Desktop.
Save joewright/e7bb33901bb912448d120c2b8c6425fc to your computer and use it in GitHub Desktop.
declare var process: {
env: {}
}
class EnvironmentConfig {
name: string
required_variable: string
optional_variable: string | undefined
constructor(env: any) {
this.name = env.NODE_ENV || 'development'
this.required_variable = env.REQUIRED_VARIABLE || undefined
if (!this.required_variable) {
throw new Error('REQUIRED_VARIABLE is not set')
}
this.optional_variable = env.OPTIONAL_VARIABLE
}
}
export const ENV = new EnvironmentConfig(process.env)
import { ENV } from './environment'
console.log(ENV.name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment