A vow-driven env validation library.
Install this package as a dependency in the project:
# npm
npm i envow
# Yarn
yarn add envow
# pnpm
pnpm add envow
# Deno
deno add npm:envow
# Bun
bun add envowcreateEnv validates the runtime environment against a Standard Schema dictionary and returns a read-only, typed object.
import { createEnv } from "envow";
import { z } from "zod";
const env = createEnv({
target: "server",
runtimeEnv: process.env,
define: {
MODE: z.enum(["development", "production"]),
PORT: z.number(),
},
});
env.PORT; // number
zodis the user's own dependency (pnpm add zod).envowaccepts any Standard Schema v1 validator (zod, valibot, arktype, ...).
createExtension builds a extension that can be composed into a createEnv call via the extends option. The parent call resolves runtimeEnv once and validates all keys (its own plus each extension's) in a single pass — extension code never touches the runtime environment.
import { createEnv, createExtension } from "envow";
import { z } from "zod";
const base = createExtension({
define: {
NODE_ENV: z.enum([
"development",
"test",
"production",
]),
LOG_LEVEL: z.enum([
"debug",
"info",
"warn",
"error",
]).default("info"),
},
});
const env = createEnv({
target: "server",
runtimeEnv: process.env,
extends: [
base,
],
define: {
PORT: z.number(),
},
});
env.NODE_ENV; // "development" | "test" | "production"
env.LOG_LEVEL; // "debug" | "info" | "warn" | "error"
env.PORT; // numberExtension define dictionaries are merged in array order; the user's define wins on key collision.
For contributing, please refer to the contributing guide.
This project is inspired by t3-env with the following differences:
-
Extensions are schema-only;
runtimeEnvis resolved alongsidecreateEnv, not inside a extension. -
More composable while nestable extensions being merged in a single validation pass.
-
Flat
define+target/conditionsinstead ofserver/client/clientPrefix.
This project is licensed under the terms of the MIT license.