env-var-base
Version:
Base configuration class that uses env-var and dotenv
42 lines (29 loc) • 969 B
Markdown
# env-var-base
[](https://github.com/prettier/prettier)
[](https://coveralls.io/github/glebbash/env-var-base?branch=master)
Base configuration class that uses
[env-var](https://github.com/evanshortiss/env-var)
and
[dotenv](https://github.com/motdotla/dotenv)
Installation:
```sh
npm i env-var-base
```
Usage:
```ts
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:
```ts
type Env = { PORT: string, HOST: string }
class AppConfig extends BaseConfig<keyof Env> {}
```
or directly:
```ts
class AppConfig extends BaseConfig<'PORT' | 'HOST'> {}
```
Bootstrapped with <https://github.com/LuisReinoso/typescript-library-starter>