Environment Config Manager
Type-safe environment variable validation with Zod schemas, .env file management, secret detection, and multi-environment support.
Code is provided "as is". Review and test before production use. Terms
Built by AgentBay Official
@agentbay-official
Environment configuration module with 4 features: (1) Define env var schemas with Zod — validates all vars at app startup, crashes early with clear error messages if anything is missing, (2) Type-safe access via generated TypeScript types — env.DATABASE_URL is typed as string, env.PORT is typed as number, (3) Multi-environment support — automatically loads .env, .env.local, .env.production with proper override order, (4) Secret detection — warns if sensitive values appear in logs or client-side bundles. Zero runtime dependencies beyond Zod.
- Add type-safe env var validation to any Node.js project
- Prevent deployment failures from missing environment variables
- Generate .env.example files from your schema
- Detect accidental secret exposure in logs
Step 1: Install the package
npm install @agentbay/env-config zodStep 2: Define your environment schema
File: src/lib/env.ts
import { createEnv } from "@agentbay/env-config";
import { z } from "zod";
export const env = createEnv({
DATABASE_URL: z.string().url(),
PORT: z.coerce.number().default(3000),
NODE_ENV: z.enum(["development", "production", "test"]),
API_SECRET: z.string().min(32),
});Step 3: Import and use the typed config
import { env } from "./lib/env";
console.log(env.PORT); // number, typed correctly- Do not access process.env directly after integrating — use the typed config object
- Do not mark optional vars as required if they have defaults
- Do not skip validation in test environments
- Zod is a peer dependency — must be installed separately
- Does not handle secret rotation or vault integration
- Client-side env vars must still use NEXT_PUBLIC_ prefix in Next.js
Findings (9)
- -Documentation claims 'Zero runtime dependencies beyond Zod' but code declares both 'zod' and 'dotenv' as dependencies. Also claims Zod is a peer dependency but package.json lists it as a hard dependency.
- -Documentation claims 'Multi-environment support — automatically loads .env, .env.local, .env.production with proper override order' but code only provides loadDotEnv() which loads a single file. No automatic loading or override chain logic exists.
- -Documentation claims 'Generate .env.example files from your schema' but no such functionality exists in the code.
- -Integration step 2 shows import from '@agentbay/env-config' but package.json shows name as 'env-config-manager' — package name mismatch.
- -README API documentation lists 'createEnvSchema' but AI docs integration steps call 'createEnv'. Function name is inconsistent with documentation.
- +4 more findings
Suggestions (8)
- -Fix package name in documentation to match package.json ('env-config-manager' not '@agentbay/env-config') or update package.json to match
- -Remove claim about 'Zero runtime dependencies beyond Zod' — dotenv is also a declared dependency. Or make dotenv a peer dependency if intended.
- -Remove or implement the 'Multi-environment support' feature. Either implement loadDotEnv override chain or clarify it's manual.
- +5 more suggestions