Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseConfig<N>

Base configuration class that uses env-var and dotenv Usage:

class AppConfig extends BaseConfig {
port = this.get('PORT').default(3000).asPortNumber()
}
const config = new AppConfig()
console.log(config.port) // 3000

Env names can also be typed like this:

type Env = { PORT: string, HOST: string }

class AppConfig extends BaseConfig<keyof Env> {}

or directly:

class AppConfig extends BaseConfig<'PORT' | 'HOST'> {}

Type parameters

  • N: string = string

Hierarchy

  • BaseConfig

Index

Constructors

Properties

Methods

Constructors

  • new BaseConfig<N>(env?: Record<N, undefined | string>): BaseConfig<N>
  • Type parameters

    • N: string = string

    Parameters

    • Optional env: Record<N, undefined | string>

      Environmental variables source, if not specified defaults to process.env with dotenv

    Returns BaseConfig<N>

Properties

env: IEnv<IOptionalVariable<Extensions> & ExtenderTypeOptional<Extensions>, unknown>

Methods

  • get(name: N): IOptionalVariable<Extensions> & ExtenderTypeOptional<Extensions>
  • Usage:

    port = this.get('PORT').default(3000).asPortNumber()
    

    Parameters

    • name: N

    Returns IOptionalVariable<Extensions> & ExtenderTypeOptional<Extensions>

Generated using TypeDoc