Provides a runtime environment variable validation pattern using Zod.
Validates all required env vars at server startup with descriptive errors — fail fast, not mid-request.
When to use
Any new environment variable is added to the project
Setting up a new service or deployment environment
Debugging "undefined env var" runtime errors
Files
env.template.ts — Runtime env validation module
Usage
Import the validated env object instead of process.env directly:
import { env } from '@/server/env';
// env.DATABASE_URL is typed string, guaranteed to exist
Convention
The env.ts file lives at src/server/env.ts
All server-only env vars (secrets, DB URLs) use z.string() with .min(1)
Public env vars (client-safe, prefixed NEXT_PUBLIC_) use a separate clientEnv export
Document all vars in .env.example with placeholder values and comments
1---2name: env-validator3description: Skill: env-validator4---56# Skill: env-validator78Provides a runtime environment variable validation pattern using Zod.9Validates all required env vars at server startup with descriptive errors — fail fast, not mid-request.1011## When to use12- Any new environment variable is added to the project13- Setting up a new service or deployment environment14- Debugging "undefined env var" runtime errors1516## Files17- `env.template.ts` — Runtime env validation module1819## Usage20Import the validated env object instead of `process.env` directly:21```ts22import { env } from '@/server/env';23// env.DATABASE_URL is typed string, guaranteed to exist24```2526## Convention27- The `env.ts` file lives at `src/server/env.ts`28- All server-only env vars (secrets, DB URLs) use `z.string()` with `.min(1)`29- Public env vars (client-safe, prefixed `NEXT_PUBLIC_`) use a separate `clientEnv` export30- Document all vars in `.env.example` with placeholder values and comments
Run npx skillmds@latest add gabrielmoreira/env-validator in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Skill: env-validator It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
gabrielmoreira (@gabrielmoreira) published this skill. Their other Agent Skills are listed on their SkillMD profile.