---
type: snippet
tags: ['zod']
status: release
ctime: 2023-06-14
mtime: 2024-03-22
---

```ts
import z from 'zod'

const envSchema = z.object({
  REACT_APP_FEATURE_VAC_ASK: z.string(),
  REACT_APP_FEATURE_RECORDS: z.string(),
  NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
})

const windowSchema = z.object({
   SOMETHING_COOL: z.string()
})

export const ENV = envSchema.parse(process.env)
export const WINDOW = windowSchema.parse(window)
```

---

- [Using Zod to safely read env variables by sergiodxa](https://sergiodxa.com/articles/using-zod-to-safely-read-env-variables)
- [GitHub - lostfictions/znv: Type-safe environment parsing and validation for Node.js with Zod schemas](https://github.com/lostfictions/znv)
- https://twitter.com/mattpocockuk/status/1615110808219918352?s=20