Secret<T> redaction
JSON.stringify, template literals, console.log, Object.keys and error messages all see [REDACTED]. Only .reveal() returns the value.
ENVShield replaces dotenv with a typed, validated configuration object. Secrets become Secret<T> values that print as [REDACTED] in logs, errors and JSON, and freeze() deletes them from process.env, so code that reads the environment afterwards, including child processes, gets nothing.
ENVShield is an open-source configuration and secrets library for Node.js that replaces dotenv. It loads .env files and other providers, validates every variable against a schema at startup, wraps secrets in a Secret<T> type that redacts itself everywhere except an explicit .reveal(), and can delete secrets from process.env once they are loaded.
dotenv copies every key into process.env, a process-wide, untyped object that every package in node_modules can read. One compromised dependency, or one console.log of the config, is enough to leak every API key the app holds. Supply-chain worms such as Shai-Hulud, in September 2025, spread by harvesting credentials like these from developer machines and CI pipelines.
ENVShield moves configuration into a typed object you control. Values are validated at startup against any Standard Schema validator, such as Zod, Valibot or ArkType, so a bad deploy fails on boot. Secrets live in a native private class field that JSON.stringify, template literals, util.inspect and error messages cannot reach, and freeze() removes them from process.env before workers or child processes start.
JSON.stringify, template literals, console.log, Object.keys and error messages all see [REDACTED]. Only .reveal() returns the value.
Deletes every secret key from process.env and leaves non-secrets in place for framework compatibility.
A typed config from any Standard Schema validator, with one startup error that names every failing field.
A predictable .env inheritance chain, with values from the CI environment taking the highest priority.
Default credential chain only, in-memory TTL cache, prefix mapping and batched reads. Errors never include ARNs or values.
Verify required variables in CI, flag .env files missing from .gitignore, and generate a typed ProcessEnv declaration.
Zod is optional: any Standard Schema validator works. Add @aws-sdk/client-secrets-manager only if you use the AWS provider. Node.js 20 or newer.
npm install @thekaloliya/envshield zodimport { envshield, s } from '@thekaloliya/envshield';
import { z } from 'zod';
const config = await envshield({
schema: {
DATABASE_URL: z.string().url(),
PORT: z.coerce.number().default(3000),
API_KEY: s.secret(z.string()),
},
});
console.log(config.API_KEY); // Secret([REDACTED])
config.API_KEY.reveal(); // the only way to read the value
envshield.freeze(config); // API_KEY is deleted from process.envdotenv loads files. ENVShield loads, validates and protects. Both read the same .env format.
| Concern | dotenv | ENVShield |
|---|---|---|
| Type safety | Every value is string | undefined | Validated, typed config object |
| Secret redaction | Secrets appear in logs and errors | Secret<T> prints [REDACTED] |
| Child processes | Inherit every variable | freeze() deletes secrets first |
| Validation | Fails at runtime, when code runs | Fails at startup, naming each field |
| Multiple environments | Manual file juggling | .env to .env.{env}.local chain |
| AWS Secrets Manager | Not supported | Built-in provider with caching |
| Runtime dependencies | None | None in the core |
Typed, validated configuration instead of string | undefined at every call site.
Secrets that cannot leak through a stray log line, error report or serialized response.
Child processes started after freeze() inherit no secrets from the parent.
Secrets Manager as a first-class provider, with local .env overrides for development.
Stated in the project’s own documentation, so you can decide where it fits.
Founder & Director, ZettaCore Labs. ENVShield is developed in the open: issues, pull requests and the full release history are on GitHub.
Cloud architecture, migration, DevOps and platform engineering - designed for predictable cost, fast recovery and deployments that are boring on purpose.
Web, mobile, SaaS and enterprise systems built on durable foundations - clear domain models, typed boundaries and tested paths.
ENVShield is an open-source, type-safe replacement for dotenv in Node.js. It validates environment variables against a schema at startup, wraps secrets in a Secret type that prints as [REDACTED] in logs and JSON, and can delete secrets from process.env after loading.
dotenv loads .env files into process.env as untyped strings. ENVShield validates them into a typed object, wraps secrets so they cannot be logged or serialized by accident, and can remove them from process.env. It reads the same .env format, so migrating is mostly a change at startup.
Yes. Zod is an optional peer dependency. Any validator that implements the Standard Schema specification works, such as Valibot or ArkType.
After freeze(), any code that reads a secret from process.env, including dependencies and child processes started later, gets undefined. Non-secret variables stay in place, and the typed config object keeps working.
Not through normal JavaScript operations. Secret returns [REDACTED] from toString, toJSON and util.inspect, and keeps the value in a native private class field. Only .reveal() returns it.
Node.js 20 or newer. The package ships ESM and CommonJS builds with TypeScript declarations, and its core has no runtime dependencies.
We implement provenance gates, LLM regression testing and secrets hygiene for teams shipping AI and fintech systems. Tell us what you run today.