Created
April 18, 2023 13:30
-
-
Save maxgfr/3a1d6b71cfc9c872527f65b2039640dc to your computer and use it in GitHub Desktop.
Example of env file with zod validation (S/O to Matt Pocok : https://www.youtube.com/watch?v=q1im-hMlKhM)
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 envVariables = z.object({ | |
DATABASE_URL: z.string(), | |
CUSTOM_STUFF: z.string(), | |
}); | |
export const ENV = envVariables.parse(process.env); | |
declare global { | |
namespace NodeJS { | |
interface ProcessEnv | |
extends z.infer<typeof envVariables> {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment