Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/pitininja/envious
- Owner: pitininja
- License: agpl-3.0
- Created: 2023-07-17T14:10:33.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-11T08:42:23.000Z (5 months ago)
- Last Synced: 2024-04-14T03:15:35.688Z (5 months ago)
- Language: TypeScript
- Size: 431 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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'
});
```