https://github.com/polioan/zod-env
Parsing .env using Zod
https://github.com/polioan/zod-env
dotenv env zod
Last synced: about 1 month ago
JSON representation
Parsing .env using Zod
- Host: GitHub
- URL: https://github.com/polioan/zod-env
- Owner: polioan
- License: mit
- Created: 2023-11-02T11:48:02.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-02T12:07:21.000Z (over 2 years ago)
- Last Synced: 2025-11-18T11:24:31.327Z (7 months ago)
- Topics: dotenv, env, zod
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@polioan/zod-env
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# zod-env
[](https://www.npmjs.com/package/@polioan/zod-env)
[](https://opensource.org/licenses/MIT)
## Install
### npm
```shell
npm i @polioan/zod-env
```
### yarn
```shell
yarn add @polioan/zod-env
```
## Usage
### Normal
```ts
import { defineEnvSchema } from '@polioan/zod-env'
import { z } from 'zod'
const env = defineEnvSchema({
schema: z.object({ NODE_ENV: z.enum(['production', 'development']) }),
})
const value = env('NODE_ENV') // "production" | "development"
const unknownValue = env('FOO') // string | undefined
```
### In bundler environment
```ts
import { defineEnvSchema } from '@polioan/zod-env'
import { z } from 'zod'
const env = defineEnvSchema({
schema: z.object({ NODE_ENV: z.enum(['production', 'development']) }),
values: {
NODE_ENV: process.env.NODE_ENV,
},
})
const value = env('NODE_ENV') // "production" | "development"
const unknownValue = env('FOO') // string | undefined
```
### With Deno or other "non process.env"
```ts
const env = defineEnvSchema({
schema: z.object({ NODE_ENV: z.enum(['production', 'development']) }),
envResolver: {
getFallback() {
return Deno.env.toObject()
},
get(key) {
return Deno.env.get(key)
},
},
})
```