A TypeScript CLI tool to validate
.env
files and auto-generate.env.example
using a Zod schema.
Managing environment variables is risky without validation.
This tool helps you:
- Validate all required environment variables before your app runs
- Check variable types and allowed values using Zod
- Auto-generate a clean
.env.example
for your team - Prevent runtime bugs due to misconfigured or missing envs
Install globally:
npm install -g env-check-ts
or use directly without installing:
npx env-check-ts validate
-
CLI commands: validate, generate
-
Type-safe validation via Zod
-
Auto-generates .env.example from schema
-
Zero-config, works out-of-the-box
-
Easily extendable for teams and CI/CD
1)Define Schema
Create src/schema.ts
:
import { z } from "zod";
export const envSchema = z.object({
NODE_ENV: z.enum(["development", "production", "test"]),
PORT: z.string(),
DATABASE_URL: z.string().url(),
});
2)Validate .env
env-check-ts validate
Example output
:
❌ Environment validation failed:
• NODE_ENV: Invalid enum value. Expected 'development' | 'production' | 'test', received 'dev'
• DATABASE_URL: Required
3)Generate .env.example
env-check-ts generate
Example output
:
env
NODE_ENV=development
PORT=
DATABASE_URL=
The project welcomes all constructive contributions. Contributions take many forms, from code for bug fixes and enhancements, to additions and fixes to documentation, additional tests, and many more!
git clone https://github.com/your-username/env-check-ts
cd env-check-ts
npm install
npm run dev
MIT