Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/glebbash/env-var-base

Class based configuration for env-var
https://github.com/glebbash/env-var-base

environment-variables hacktoberfest typescript

Last synced: about 2 months ago
JSON representation

Class based configuration for env-var

Awesome Lists containing this project

README

        

# env-var-base

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Coverage Status](https://coveralls.io/repos/github/glebbash/env-var-base/badge.svg?branch=master)](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 {}
```

or directly:

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

Bootstrapped with