v1.7.0See what's new

Type-safe configuration with Zod

Load configuration variables from multiple sources type safely using Zod.

$npm install zod-config zod
config.ts
import {  } from "zod";
import {  } from "zod-config";
import {  } from "zod-config/env-adapter";
import {  } from "zod-config/json-adapter";

const  = await ({
  : .({
    : ..().(3000),
    : .(),
  }),
  : [({ : "./config.json" }), ()],
});

.port;
port: number

Type safety

A Zod schema validates your configuration, and the result is fully typed.

Tiny

No dependencies, tree-shaking friendly. Adapters are separate entry points.

Flexible

Combine adapters to read from several sources, deep-merged in order, or write your own.

Async and sync

loadConfig for any adapter, loadConfigSync when every adapter is synchronous.

Adapters

Type-safe environment variables

One env.ts with separate server and client schemas, checked when the build starts. Public prefixes are enforced, and reading a server variable in the browser throws.