Basic example
See the code snippet below for a usual setup in projects
config.ts
import { createConfigLoader } from 'neat-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
.freeze() // freezes the object so no changes can be made at runtime
.load(); // this returns the fully type configuration (type infered from schema)