File

src/module/config/entity/config.ts

Index

Properties
Methods

Properties

Private Static variables
Type : object
Default value : {}

Methods

Static get
get(name: string)
Parameters :
Name Type Optional
name string No
Returns : any
Static populate
populate()
Returns : void
Static push
push(name: string, value: any)
Parameters :
Name Type Optional
name string No
value any No
Returns : boolean
import { ConfigVariableNotFoundException } from '../../routing/exception/config.variable.not.found.exception'
import * as dotenv from 'dotenv'

export abstract class Config {

	private static variables: object = {}

	static get(name: string): any {

		if (this.variables.hasOwnProperty(name)) {

			return this.variables[name]

		} else {

			throw new ConfigVariableNotFoundException(name)

		}

	}

	static push(name: string, value: any): boolean {

		const overwritten: boolean = this.variables[name] !== undefined

		this.variables[name] = value
		return overwritten

	}

	static populate(): void {

		dotenv.config()
		for (const key of Object.keys(process.env)) {

			this.push(key, process.env[key])

		}

	}

}

result-matching ""

    No results matching ""