Environment Configuration

Validate and centralize environment variables with Zod for Next.js and Node.js apps.

Updated Jan 26, 2026
One-click install
npx skills add https://github.com/theofernandezz/ai-library --skill environment-configuration-theofernandezz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Environment Configuration
Source: https://github.com/theofernandezz/ai-library/tree/main/.opencode/skills/generic/env-config
Command: npx skills add https://github.com/theofernandezz/ai-library --skill environment-configuration-theofernandezz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Validates and centralizes environment variable handling at startup, ensuring explicit types and early failures to prevent cryptic runtime errors.

Core Features & Use Cases

  • Centralized env validation with Zod for all required and optional variables.
  • Server/public separation to keep sensitive keys on the server and safe keys on the client.
  • Typed optional variables and import-from-lib/env usage to avoid direct process.env access.

Quick Start

Import the validated env from '@/lib/env' and start using env values directly in your app.

Frequently Asked Questions about Environment Configuration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate environment variables at startup in a Node.js app?

Validate environment variables at startup by defining a centralized Zod schema. This checks required and optional vars immediately during initialization, providing clear errors and preventing cryptic runtime failures later.

What is the best way to separate server and public environment variables in Next.js?

Separate server and public environment variables in Next.js by applying a centralized validation schema. This keeps sensitive server keys secure while safely exposing public keys to the client boundary.

How do I prevent undefined process.env errors in my application?

Prevent undefined process.env errors by importing validated values from a centralized lib/env file instead of accessing process.env directly. This enforces typed optional variables and defaults at startup.

Can I use Zod to set default values for optional environment variables?

Yes, you can use Zod to set defaults for optional environment variables. The centralized schema validates types and applies fallback values automatically at startup, ensuring your app always receives valid configuration.

Why should I centralize environment configuration instead of using process.env directly?

Centralizing environment configuration prevents runtime failures by validating explicit types early. Importing from a lib/env file avoids direct process.env access, ensuring sensitive keys stay on the server and types remain consistent.