Last active
January 30, 2024 13:37
-
-
Save joao-coimbra/caf0a81d1f59d566b582b2ee8f99cc17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { z } from "zod"; | |
| const nodeEnv = z.enum(["development", "production"]); | |
| function requiredOn(env: z.infer<typeof nodeEnv>) { | |
| return (value: any) => !(env === process.env.NODE_ENV && !value); | |
| } | |
| const envSchema = z.object({ | |
| NODE_ENV: nodeEnv.default('development'), | |
| DATABASE_URL: z.string().min(1), | |
| REQUIRED_ENV: z.string().refine(requiredOn('production')) | |
| // MORE VARIABLES | |
| }) | |
| export const env = envSchema.parse(process.env) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment