One error at a time
Most setups crash on the first missing variable. You fix it, redeploy, and meet the next one. envyak checks the whole schema and lists every problem with a fix hint.
v0.1.1, zero dependencies, 2.6 kBNodeBunDenoEdge
Describe your configuration once. envyak reads it, parses it into real numbers, booleans, URLs and dates, infers the exact TypeScript type, and when something is wrong it tells you about every variable in one message, without ever printing a secret.
$ npm i envyak01 Playground
This runs the real library in your browser against the sample schema. Break something and the error report updates as you type.
One checkpoint per variable. Pick a flag to read its log.
Tab inserts two spaces. Press Escape, then Tab, to move focus out of the editor.
// typeof config, inferred with no annotations
type Config = {
readonly PORT: number;
readonly DEBUG: boolean;
readonly DATABASE_URL: string;
readonly NODE_ENV: 'development' | 'production' | 'test';
readonly API_KEY: string;
readonly TAGS: readonly string[] | undefined;
readonly RATIO: number;
readonly START: Date;
readonly CONFIG: unknown;
readonly ADMIN_EMAIL: string;
};Secret values stay masked when the object is logged or serialized. The real value is still there for your code.
02 Why it exists
Most setups crash on the first missing variable. You fix it, redeploy, and meet the next one. envyak checks the whole schema and lists every problem with a fix hint.
A failed check that prints the value it rejected can leak an API key into your log pipeline. Variables marked secret are never printed, not in errors and not when the config object is logged.
process.env only holds strings. envyak gives you numbers, booleans, URLs, lists, JSON and dates, with types inferred exactly: optional means T | undefined, default means T.
03 How to
Three steps, no config files and no schema library to learn.
One package with no dependencies. It ships ESM, CommonJS and its own types.
$ npm i envyakPick a validator for each key and add a default, an example or secret: true where it helps.
import { env, port, url, str } from 'envyak';
export const config = env({
PORT: port({ default: 3000 }),
DATABASE_URL: url(),
API_KEY: str({ secret: true }),
});Read config.PORT as a number anywhere in your app. If something is wrong, startup stops with one clear report.
import { config } from './config.js';
server.listen(config.PORT);
// config.PORT is a number, typed as number04 Features
No generics to write. oneOf gives a union of literals, list gives a readonly array, optional adds undefined only when there is no fallback.
EnvError lists each missing or invalid variable with what was expected, what was received and how to fix it.
secret: true masks the value in errors, toString, JSON.stringify and util.inspect, in Node, Bun and Deno.
2.6 kB min+gzip for the whole library, less when your bundler drops the validators you do not import.
Reads process.env by default, falls back to Deno.env, and takes any object as source: Workers bindings, import.meta.env, a parsed file.
bool accepts exactly true, false, 1, 0, yes, no, on and off. Numbers reject hex and Infinity. Dates must be real calendar dates.
devDefault fills a value while you develop and makes it required when NODE_ENV is production.
The config object, its lists and its JSON values are frozen, so nothing rewrites your settings at runtime.
05 API
Every validator takes the shared options default, devDefault, optional, description, example and secret.
| Validator | Accepts | Type |
|---|---|---|
str() | any non-empty string, minLength, maxLength, pattern | string |
num() | finite decimal number, min, max | number |
int() | safe integer in base 10, min, max | number |
port() | integer from 1 to 65535 | number |
bool() | true false 1 0 yes no on off, any case | boolean |
url() | absolute URL, optional protocols | string |
email() | one @, no spaces, a dot in the domain | string |
oneOf([...]) | one of the listed strings | 'a' | 'b' |
list(item) | separated items, each parsed by a validator | readonly T[] |
json<T>() | any JSON text, deep frozen | T |
date() | ISO 8601 date or date time | Date |
custom(fn) | whatever your function returns | R |
import { env, port, bool, url, oneOf, str } from 'envyak';
export const config = env({
PORT: port({ default: 3000 }),
DEBUG: bool({ default: false }),
DATABASE_URL: url(),
NODE_ENV: oneOf(['development', 'production', 'test']),
API_KEY: str({ secret: true }),
});
config.PORT; // number
config.NODE_ENV; // 'development' | 'production' | 'test'
String(config); // {"PORT":3000,...,"API_KEY":"[secret]"}EnvError: 3 environment variables are missing or invalid:
DATABASE_URL is missing
fix: set DATABASE_URL, for example DATABASE_URL=https://example.com
PORT expected a port number from 1 to 65535, got "70000"
fix: set PORT, for example PORT=3000
API_KEY expected a string of at least 32 characters, got a secret value (hidden)
fix: set API_KEY to a string of at least 32 characters// node --env-file=.env server.js
import { env, port, url, str, bool } from 'envyak';
export const config = env({
PORT: port({ default: 3000 }),
DATABASE_URL: url({ protocols: ['postgres', 'postgresql'] }),
SESSION_SECRET: str({ secret: true, minLength: 32 }),
DEBUG: bool({ devDefault: true, default: false }),
});
// CommonJS works too: const { env, port } = require('envyak');06 Benchmarks
Parsing the same 8 variables, median of 5 runs. Higher is better. Node v24.16.0 on Windows 10 x64, a modest desktop.
Hand written checks are the ceiling: no messages, no masking, no reuse. envyak and @t3-oss/env-core + zod trade places from run to run here; treat them as equally fast.
Minified and gzipped, measured with the same bundler for every library, for a schema with four validators.
Checked against the published packages. Each of them does something envyak does not, so pick what fits.
| Compared honestly | envyak | envalid 9 | t3 env-core | znv |
|---|---|---|---|---|
| Runtime dependencies | none | none | a Standard Schema library | zod (peer) |
| Reports every error | yes | yes | yes | yes |
| Masks secret values | yes | no | no | no |
| Type inference | yes | yes | yes | yes |
| On failure | throws EnvError | prints, then exits the process | logs issues, throws | throws a formatted list |
| Unique strength | secret masking, exact types with no schema library | strict proxy that throws on unknown keys | client and server split for frameworks | the full power of zod schemas |
07 Compatibility
Node.js 18 and later, ESM and CommonJS
Bun, tested in CI
Deno 2, tested in CI
Edge runtimes and Workers, pass the source
Browsers and bundlers, tree shakeable
TypeScript 5.0 and later for the types
08 FAQ
09 Summit
Install envyak, describe your variables once, and let every deploy tell you exactly what is missing before it ever reaches production.