Skip to Content
Zod Config

Synchronous loading

Use loadConfigSync when all your adapters are synchronous.

loadConfig is asynchronous to allow for asynchronous adapters. If you only use synchronous adapters, use loadConfigSync, which returns the configuration directly instead of a promise.

These built-in adapters are synchronous and work with loadConfigSync:

When you write your own adapter for loadConfigSync, implement the SyncAdapter type instead of Adapter. The schema must be synchronous too (no async refinements or transforms).

import {  } from 'zod';
import {  } from 'zod-config';
import {  } from 'zod-config/env-adapter';
import {  } from 'zod-config/json-adapter';
import path from 'path';

const  = .({
  : .().(/^\d+$/),
  : .(),
});

const  = path.(, 'config.json');

const  = ({
  : ,
  : [({ :  }), ()],
});