From harness-claude
Manages Node.js environment configuration using process.env, dotenv, and Zod validation for 12-factor apps. Validates required variables at startup and enables type-safe access across dev, staging, and production.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Manage environment configuration with process.env, dotenv, and validation for 12-factor apps
Configures and validates Next.js environment variables securely with Zod and t3-env, enforces server-only boundaries, exposes safe client vars, and handles multi-environment setups.
Analyzes environment variables in code, generates .env.example templates, validates configurations and types, documents variables with examples, and provides naming and security best practices.
Manages env vars with better-env: typed config schemas, Vercel sync from local files, prebuild validation. Useful for type-safe envs in Vercel deploys.
Share bugs, ideas, or general feedback.
Manage environment configuration with process.env, dotenv, and validation for 12-factor apps
.env files with dotenv (or Node.js 20.6+ built-in):// Node.js 20.6+: use --env-file flag
// node --env-file=.env app.js
// Or with dotenv package
import 'dotenv/config';
import { z } from 'zod';
const EnvSchema = z.object({
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
PORT: z.coerce.number().default(3000),
DATABASE_URL: z.string().url(),
REDIS_URL: z.string().url().optional(),
API_KEY: z.string().min(1),
LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
});
export const env = EnvSchema.parse(process.env);
// Throws at startup if any required variable is missing or invalid
// env.PORT is number, env.DATABASE_URL is string
// No more process.env.PORT! (which is always string | undefined)
const server = app.listen(env.PORT);
.env files:# .env — defaults for local development (committed)
NODE_ENV=development
PORT=3000
LOG_LEVEL=debug
# .env.local — local overrides and secrets (gitignored)
DATABASE_URL=postgresql://localhost:5432/myapp
API_KEY=dev-key-123
.env.example as documentation:# .env.example — committed, shows all required variables
NODE_ENV=development
PORT=3000
DATABASE_URL=postgresql://user:pass@host:5432/db
API_KEY=your-api-key-here
const config = {
development: {
logLevel: 'debug',
corsOrigin: '*',
},
production: {
logLevel: 'info',
corsOrigin: 'https://myapp.com',
},
test: {
logLevel: 'error',
corsOrigin: '*',
},
}[env.NODE_ENV];
Never hardcode secrets. Use environment variables for:
Add to .gitignore:
.env.local
.env.*.local
.env.production
The 12-factor app methodology recommends storing configuration in environment variables. This separates config from code and enables different configurations per deployment without code changes.
process.env limitations:
string | undefined — no numbers, booleans, or arraysundefined, not errors — code can run with missing config and fail laterValidation at startup with Zod solves all three problems. The application fails immediately with a clear error message if any required variable is missing.
Node.js 20.6+ --env-file: Built-in .env loading without the dotenv package. Supports multiple files: node --env-file=.env --env-file=.env.local app.js.
Trade-offs:
.env files are convenient for development — but should never be used in production (use the deployment platform's secrets management)process.env is global — consider dependency injection for testabilityhttps://nodejs.org/api/process.html#processenv