env-check-pro
v1.0.0
Published
A stylish and powerful environment variable validator for Node.js using Zod.
Maintainers
Readme
Are you tired of debugging your application only to find out you forgot to add a variable to your .env file? env-check-pro solves this problem by validating your environment variables at startup, providing beautiful, easy-to-read error messages in the terminal, and giving you 100% type safety.
✨ Why env-check-pro?
- 🛡️ Type-safe: Built on top of Zod, giving you full autocomplete and type inference.
- 🎨 Beautiful Developer Experience (DX): Uses
picocolorsto print highly readable, organized error logs to the terminal when validation fails. - 🚀 Fail Fast: Instantly stops process execution (
process.exit(1)) on invalid environment variables. - 📦 Zero Config: Works right out of the box with CommonJS and ESModules.
🎨 Error Output Example
When an environment variable is missing or invalid, the console output looks like this. It is designed to be instantly readable:
✖ Environment variable validation failed!
► DATABASE_URL: Invalid URL
► PORT: Invalid string: must match pattern /^\d+$/
► API_KEY: API key must be at least 10 characters long
Please check your .env file or environment variables.📦 Installation
npm install env-check-pro zod
# or
yarn add env-check-pro zod
# or
pnpm add env-check-pro zod🚀 Usage Guide
Create a file where you define and export your validated environment variables (for e.g., src/env.ts):
import { validateEnv, z } from 'env-check-pro';
// 1. Define your schema using Zod
const envSchema = z.object({
DATABASE_URL: z.string().url(),
PORT: z.string().regex(/^\d+$/).transform(Number),
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
API_KEY: z.string().min(10, 'API key must be at least 10 characters long'),
});
// 2. Validate process.env
// If it fails, it prints a beautiful error message and exits the process!
export const env = validateEnv(envSchema);Then use it anywhere in your app with perfect auto-complete:
import { env } from './env';
console.log(`Server starting in ${env.NODE_ENV} mode...`);
console.log(`Database connected at ${env.DATABASE_URL}`);
// env.PORT is strictly typed as a Number!⚙️ Advanced Options
You can pass an options object as the second argument to validateEnv:
const env = validateEnv(schema, {
// Do not exit process (process.exit(1)) upon failure. Default is false.
skipExit: true,
// Custom message printed when validation passes
successMessage: '✅ All environment variables are ready!',
// Custom Object to validate against instead of process.env
env: customEnvObject
});📄 License
MIT © Ahmet Ozcan
