0.1.1 • Published 1 year ago

zennv v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

NameDefaultDescriptionRequired
dotenvtrueUses dotenv to load your schema from process.envNo
schemaZod schema to parse your environment variables withYes
dataprocess.envAn object to use instead of process.envNo
0.1.1

1 year ago

0.1.0

1 year ago