@zodyac/env
v1.1.8
Published
Parse environment variables with zod
Downloads
12
Maintainers
Readme
Zod Environment parser
A part of Zodyac toolbox.
This package allows you to parse your .env
file or process.env
safely.
Installation
Install the package:
npm i @zodyac/env
Usage
Define your environment schema:
import { z } from 'zod';
const env_schema = z.object({
// ... your zod schema
});
Don't forget to use z.coerce
on types other than String!
Parse your environment using parse()
:
import { parse } from '@zodyac/env';
const env = parse(env_schema);
You can also use z.default()
to provide a fallback.
Now your env
infers types from Zod schema.
Configuration
By default, parse
falls back to process.env
, if no .env
file was found.
You can ignore process.env
fallback by adding:
const env = parse(env_schema, {
ignoreProcessEnv: true,
});
Or you can provide it's path using path
parameter:
const env = parse(env_schema, {
path: 'path/to/env.file',
ignoreProcessEnv: true,
});
License
MIT