Guide

Basic example#

See the code snippet below for a usual setup in projects

import { createConfigLoader } from '@neato/config';
import { z } from 'zod';
 
const schema = z.object({
  port: z.coerce.number(),
});
 
export const config = createConfigLoader()
  .addFromEnvironment("CONF_") // loads CONF_PORT=8080
  .addFromFile(".env") // loads PORT=8080 from file
  .addFromFile(".json") // loads { "port": 8080 } from file
  .addZodSchema(schema) // validates the loaded data to make sure it follow the schema
  .load(); // this returns the fully type configuration (type infered from schema)