- Home
- Skills
- Andrelandgraf
- Fullstackrecipes
- Env Validation
env-validation_skill
- TypeScript
8
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill andrelandgraf/fullstackrecipes --skill env-validation- SKILL.md11.8 KB
Overview
This skill validates environment variables on server start and before builds to catch missing or invalid values early. It provides clear, actionable error messages and warnings about unused .env entries so builds and runtime failures are prevented.
How this skill works
On server startup, import config modules that run schema validation so missing or invalid env values cause the process to fail fast. A CLI script loads .env files using Next.js load order, discovers src/lib/*/config.ts files, imports them to trigger validation, and reports validation errors and unused variables. The script exits with code 1 on validation failures so CI and prebuild hooks stop broken builds.
When to use it
- During local development to fail fast when required env vars are missing
- As a prebuild step in CI or Vercel to prevent broken builds
- When packages read env vars internally and you want early detection
- To find and clean up unused variables in .env files
- Before releasing to production to ensure all required config is present
Best practices
- Import config modules from a central instrumentation file so validation runs on server start
- Add the validator to prebuild or CI scripts so builds stop on missing/invalid vars
- Keep config validation schemas explicit and descriptive to produce actionable errors
- Ignore common system/framework env vars when reporting unused entries
- Run the validator in both development and production modes to catch environment-specific issues
Example use cases
- Fail the server startup with a clear message when a required API key is not set
- Run env:validate:prod in CI as part of prebuild to block deployments with missing vars
- Detect environment variables defined in .env.local that are no longer used
- Validate configs for third-party SDKs that read process.env internally
- Integrate the script into a lint or CI pipeline to enforce env hygiene
FAQ
No. Unused variables only generate warnings; validation errors for missing/invalid required vars are what cause the script to exit with code 1.
How does this detect which env vars are used?
The script proxies process.env to record accesses while importing each config file, then compares referenced vars against variables defined in loaded .env files.