Environment Contracts for Node.js
Deterministic runtime validation powered by statically generated schema manifests.
envwise gives you code-first env declarations (builder + decorators), AST extraction at build time, and a strict runtime that validates from a committed manifest (envwise.schema.json) with zero runtime scanning.
- π― Deterministic by design: runtime only reads schema + configured sources.
- π§© Hybrid workflow: author in code, ship generated artifacts.
- π§ͺ Strict parsing:
bool,int,float,json,list<T>,url,duration,bytes. - π Serializable rule DSL: cross-field rules that survive extraction.
- π Security-first diagnostics: secrets masked by default.
- β CI drift enforcement: ensure schema/docs/templates stay in sync.
Code (builder / decorators)
|
| envwise generate (AST extraction)
v
envwise.schema.json + outputs
(.env.example, markdown, html, k8s, json-schema)
|
| loadEnv({ schema, sources })
v
Deterministic runtime validation
| Capability | envwise |
|---|---|
| Builder API (TS + JS) | β |
| Decorator API (TS) | β |
| Runtime file/module scanning | β |
| Startup / Lazy / Manual modes | β |
| Strict typed parsing | β |
| Serializable cross-field rules | β |
.env.example / docs / html / k8s / json-schema outputs |
β |
| CI schema drift checks | β |
pnpm add @envwise/core
pnpm add -D @envwise/cliimport { defineEnv, rule } from '@envwise/core';
export const schema = defineEnv({ projectName: 'my-app' })
.string('NODE_ENV').oneOf(['development', 'production']).default('development')
.int('PORT').default(3000).min(1).max(65535)
.bool('USE_DB').default(false)
.string('DB_URL').optional().secret().mode('lazy')
.rule(rule('db-required', (r) => r.when('USE_DB').equals(true).thenRequire(['DB_URL'])))
.build();envwise generate \
--entry ./src/env.ts \
--out ./envwise.schema.json \
--formats dotenv,markdown,html,json-schema,k8s,tableimport manifest from './envwise.schema.json';
import { loadEnv, processEnvSource, dotenvSource, argvSource } from '@envwise/core';
const env = loadEnv({
schema: manifest,
sources: [dotenvSource({ optional: true }), processEnvSource(), argvSource()],
});
console.log(env.get('PORT'));Use fluent, chainable declarations with type-safe runtime access.
import { EnvSchema, EnvVar, Rule } from '@envwise/decorators';
import { rule } from '@envwise/core';
@EnvSchema({ projectName: 'my-app' })
@Rule(rule('db-required', (r) => r.when('USE_DB').equals(true).thenRequire(['DB_URL'])))
class AppEnv {
@EnvVar({ key: 'PORT', type: 'int', default: 3000 })
port!: number;
@EnvVar({ key: 'USE_DB', type: 'bool', default: false })
useDb!: boolean;
@EnvVar({ key: 'DB_URL', type: 'string', required: false, mode: 'lazy', secret: true })
dbUrl!: string;
}envwise generate --entry ./src/schema.ts --out ./envwise.schema.json
envwise check --entry ./src/schema.ts --out ./envwise.schema.jsonConfig file support: envwise.config.ts | envwise.config.js | envwise.config.json.
- π Contract manifest (
envwise.schema.json) - π§
.env.example - π Markdown docs
- π HTML docs
- π JSON schema for manifest
- βΈοΈ Kubernetes templates (
ConfigMap+Secretplaceholders)
- Diagnostics levels:
safe | verbose | off - Secret values are masked by default
- Secret values require explicit nuclear opt-in (
allowSecretValueLogging: true)
envwise check fails if generated files drift from source declarations.
Recommended CI steps:
pnpm install
pnpm lint
pnpm test
pnpm build
pnpm envwise:generate
pnpm envwise:checkZod is excellent for runtime object validation; envwise focuses on env contracts + static extraction + deterministic startup/runtime env validation + generated infra/docs artifacts.
envalid focuses on runtime env parsing; envwise adds extraction, manifest versioning, richer outputs, decorator support, and CI schema drift checks.
- Quickstart
- Builder Guide
- Decorators Guide
- CI Enforcement Guide
- Migration from Zod/envalid
- API Reference
- AI Agent Usage Guide
@envwise/schema: shared manifest types + JSON schema@envwise/core: runtime, parser, rule engine, outputs, sources@envwise/decorators: decorator authoring API@envwise/cli: AST extraction + generators + drift checks
pnpm install
pnpm lint
pnpm test
pnpm build
pnpm envwise:generate
pnpm envwise:checkLocal publish (no provenance, required outside GitHub Actions OIDC):
npm login
pnpm npm:whoami
pnpm changeset:publish:localCI publish (with provenance):
- Uses
.github/workflows/release.yml - Sets
NPM_CONFIG_PROVENANCE=true - Uses npm trusted publishing (OIDC) or
NPM_TOKEN
If publish fails with 404 for @envwise/*, ensure your npm account/org owns the @envwise scope and has publish permission.
MIT.