Skip to content

Instantly share code, notes, and snippets.

@meiazero
meiazero / env.ts
Created April 14, 2024 15:40
Trick to extend node.js native `ProcessEnv` interface to include your own environment variables with zod
import { z } from "zod";
export const envVariables = z.object({
// your env variables like:
HOST: z.string(),
PORT: z.number().int().positive(),
});
// Parse the environment variables to ensure they match the schema
envVariables.parse(process.env);

Demo:

Spoiler warning

Spoiler text. Note that it's important to have a space after the summary tag. You should be able to write any markdown you want inside the <details> tag... just make sure you close <details> afterward.

console.log("I'm a code block!");