Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/pitininja/envious

Environment variable parsing using Dotenv & Typebox
https://github.com/pitininja/envious

Last synced: about 1 month ago
JSON representation

Environment variable parsing using Dotenv & Typebox

Awesome Lists containing this project

README

        

# Envious

> Environment variable parsing using Dotenv & Typebox

## Install

```shell
npm i @pitininja/envious
```

## Usage

* Environment variables are automatically loaded using [Dotenv](https://github.com/motdotla/dotenv)
* Refer to the [official Typebox documentation](https://github.com/sinclairzx81/typebox) for how to write a Typebox schema

```typescript
import { Type } from '@sinclair/typebox';
import { envious } from '@pitininja/envious';

export const schema = Type.Object({
STRING_VAR: Type.String(),
NUMBER_VAR: Type.Integer(),
BOOLEAN_VAR: Type.Boolean(),
OPTIONAL_VAR: Type.Optional(Type.String())
});

/**
Parse your environment variables.
If the environment variables don't match the schema, an error will be thrown.
*/
const env = envious(schema);

/**
You can provide default values as second parameter of the envious function.
*/
const envWithDefaults = envious(schema, {
STRING_VAR: 'Example',
NUMBER_VAR: 123,
BOOLEAN_VAR: true,
OPTIONAL_VAR: 'Example'
});
```