Back to Insights/Open Source

EnvKit: Framework-Agnostic Environment Validation, Secrets Masking, and Auto-Generation

NovaEdge Logo

Amit Kumar Raikwar

Lead Strategist

June 11, 20268 min read
EnvKit: Framework-Agnostic Environment Validation, Secrets Masking, and Auto-Generation

Managing environment variables across development, staging, and production is notoriously error-prone. Meet EnvKit—a zero-dependency, framework-agnostic library that validates environment schemas using Zod, dynamically masks secrets in logs, and automatically synchronizes .env.example templates.

The Silent Configuration Crises

Every developer has lived through this scenario: you deploy a critical update, and the production build instantly crashes because a new API token was added to the schema but forgotten in the environment settings. Or worse: a debug log statement accidentally writes your database credentials or OAuth secret in plain text to a logging service like Datadog or CloudWatch.

Managing environment variables should not be an exercise in vigilance. While libraries like dotenv parse config files, they don't validate types. Existing schema validators are often tied to specific frontend frameworks or fail to protect secrets from being logged. We built EnvKit to solve these operational pain points once and for all.

Introducing EnvKit

EnvKit is a lightweight, zero-dependency (other than Zod) utility library designed to load, validate, and mask environment variables in any JavaScript or TypeScript project. It works seamlessly in both Node.js server environments and client-side bundlers.

bash@novaedgedigitallabs/citykit
npm install @novaedgedigitallabs/envkit zod

With EnvKit, you declare your application config schema in a central file. Zod parses and casts your variables, ensuring strings, numbers, booleans, and custom enums match your exact criteria. If a variable is invalid or missing, your application fails fast at startup with a clean error message, preventing broken runtimes.

1. Type-Safe Environment Variables

Instead of referencing raw untyped values like process.env.PORT (which TypeScript treats as an optional string), EnvKit parses your variables into a fully-typed object. Port strings are coerced to numbers, booleans are cast correctly, and missing variables trigger clear validation errors immediately.

typescript@novaedgedigitallabs/citykit
import { createEnv } from '@novaedgedigitallabs/envkit';
import { z } from 'zod';

export const env = createEnv({
  schema: {
    DATABASE_URL: z.string().url(),
    JWT_SECRET: z.string().min(32),
    PORT: z.coerce.number().default(3000),
    NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
  },
  secrets: ['JWT_SECRET', 'DATABASE_URL'],
  generateExample: true, // Automatically append new keys to .env.example
});

By calling createEnv, you get an exportable env object that provides auto-complete and static typing throughout your codebase. If you try to compile or run the code without DATABASE_URL specified in your local environment, EnvKit will output a breakdown of Zod errors and halt execution before any requests are handled.

2. Automatic Secrets Masking

One of EnvKit's standout features is its built-in logging protection. In production, developers frequently write objects like console.log(config) or console.log(process.env) to debug state. When secrets are printed, they are written to persistent log aggregation tools, exposing sensitive credentials.

EnvKit prevents this by letting you define a secrets list. The returned configuration object uses ES6 Proxies and custom inspection hooks to intercept formatting. If you log the configuration object or any individual secret key, EnvKit automatically masks it.

typescript@novaedgedigitallabs/citykit
console.log(env.PORT);
// → 3000 (real value is accessible)

console.log(env.JWT_SECRET);
// → 'my-ultra-secure-thirty-two-character-key' (accessible via direct call)

console.log(env);
// → { PORT: 3000, NODE_ENV: 'development', JWT_SECRET: '[MASKED]', DATABASE_URL: '[MASKED]' }

This proxy-based security ensures your application logic can read the credentials perfectly (e.g. when connecting to your database), but any accidental log serialization will print [MASKED], preserving your application security.

3. Smart Template Generation (CLI & Runtime)

When working in a team, one engineer adding a new key to their .env file usually forgets to update the shared .env.example file. The next developer pulls the changes and is left debugging why their local environment is broken.

EnvKit solves this by shipping with a dedicated CLI and runtime sync mechanism. Running the command parses your files and appends missing keys to your template file without erasing existing notes, descriptions, or comment blocks.

bash@novaedgedigitallabs/citykit
npx envkit generate
# → ✓ .env.example updated with 4 new keys

You can easily customize custom environment file paths for staging, production, or microservices using CLI flags. It supports ESM and CJS natively, making it a drop-in replacement for dotenv configuration setups in legacy and modern projects alike.

Framework Agnostic by Design

Unlike other framework-specific validation solutions, EnvKit is built to run anywhere. It performs equally well in an Express API, a NestJS microservice, a Vite frontend, or a standalone CLI utility. By separating configuration schema logic from the framework, you maintain a consistent environment validation standard across your entire organization.

Check out @novaedgedigitallabs/envkit on npm and secure your environment configurations today. Contributions are always welcome on our GitHub repository!

Frequently Asked Questions

EnvKit is a framework-agnostic environment variable manager and validator. It uses Zod to validate configuration schemas, automatically masks sensitive variables in runtime logs, and provides a CLI tool to generate and synchronize `.env.example` templates dynamically.

When you define a variable as a secret in your configuration schema, EnvKit wraps the validated output object. If any process attempts to log the variable or the configuration object, EnvKit intercepts standard inspection/string coercion and outputs `[MASKED]` instead of leaking the sensitive value.

Yes, EnvKit is completely framework-agnostic and supports both ESM and CommonJS. You can use it in Next.js (both client and server components), Vite, Express, NestJS, or raw Node.js/TypeScript scripts.

The EnvKit CLI (`npx envkit generate`) reads your schema file directly, detects newly added variables, and appends them to your `.env.example` file without erasing existing descriptions, formatting, or comments. It keeps development templates up to date with zero manual synchronization.
#npm#Node.js#TypeScript#Open Source#Security#Zod#Environment Variables
NovaEdge Logo

About Amit Kumar Raikwar

NovaEdge Digital Labs is a team of designers, developers, and strategists dedicated to pushing the boundaries of digital innovation in 2026.

Learn more about the team

Keep Reading

Related Insights