Skip to content

tomanagle/zennv

Repository files navigation

zennv

Parses environment variables using a Zod schema for type and runtime validation

Getting started

Install the package

yarn add zennv
pnpm add zennv
npm i zennv

Define a Zod schema

import z from 'zod';

const envSchema = z.object({
  PORT: z.number(),
  HOST: z.string().default('localhost'),
  IS_DEV: z.boolean(),
  IS_DEFAULT_TRUE: z.boolean().default(true),
  IS_DEFAULT_FALSE: z.boolean().default(false),
  IS_OPTIONAL: z.string().optional(),
})

Pass the schema to zennv

import zennv from 'zennv';

const env = zennv({
  dotenv: true,
  schema: envSchema,
});

Use the environment variables

const { PORT, HOST, IS_DEV, IS_DEFAULT_TRUE, IS_DEFAULT_FALSE, IS_OPTIONAL } = env;

Options

Name Default Description Required
dotenv true Uses dotenv to load your schema from process.env No
schema Zod schema to parse your environment variables with Yes
data process.env An object to use instead of process.env No

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published