mirror of
https://github.com/standardnotes/server
synced 2026-10-07 09:13:32 -04:00
25 lines
516 B
TypeScript
25 lines
516 B
TypeScript
import { config, DotenvParseOutput } from 'dotenv'
|
|
import { injectable } from 'inversify'
|
|
|
|
@injectable()
|
|
export class Env {
|
|
private env?: DotenvParseOutput
|
|
|
|
public load(): void {
|
|
const output = config()
|
|
this.env = <DotenvParseOutput>output.parsed
|
|
}
|
|
|
|
public get(key: string, optional = false): string {
|
|
if (!this.env) {
|
|
this.load()
|
|
}
|
|
|
|
if (!process.env[key] && !optional) {
|
|
throw new Error(`Environment variable ${key} not set`)
|
|
}
|
|
|
|
return <string>process.env[key]
|
|
}
|
|
}
|