@nothinghere/env-validator
v1.0.1
Published
Validate environment variables using Zod schemas before your application starts.
Downloads
71
Readme
@nothinghere/env-validator
A lightweight utility to validate environment variables at startup using Zod. If validation fails, it prints a clear, colored error message and exits the process, preventing your app from running with a broken configuration.
Installation
npm install @nothinghere/env-validator
# or
pnpm add @nothinghere/env-validatorUsage
import { z } from "zod";
import { guardEnv } from "@nothinghere/env-validator";
const env = guardEnv(
z.object({
PORT: z.string(),
NODE_ENV: z.enum(["development", "production"]),
}),
);if no environment variables were defined:
ENVIRONMENT VALIDATION FAILED
NODE_ENV: Invalid option: expected one of "development"|"production"
PORT: Invalid input: expected number, received NaN
Please check your .env file or the environment variables.