Environment variable parsing using Dotenv & Typebox
npm i @pitininja/envious
- Environment variables are automatically loaded using Dotenv
- Refer to the official Typebox documentation for how to write a Typebox schema
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_WITH_DEFAULT: Type.Boolean({ default: false }),
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);