Skip to Content
Zod Config

Combine multiple adapters

Read configuration from several sources and deep-merge it in order.

You can combine multiple adapters to load the configuration from different sources. Zod Config deeply merges the configuration from the different sources, following the order of the adapters: later adapters override earlier ones.

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  = await ({
  : ,
  : [
    ({ :  }),
    (), // overrides values from config.json
  ],
});

When combining multiple adapters, null values from later adapters override existing values. You can use this on purpose to reset a value.

If one adapter fails, the data from the others is still used, and a warning is logged. See Silent mode.