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)
index.ts
import { config } from './config.ts';
import express from 'express';

const app = express();

app.get('/', (req, res) => {
  res.send({
    data: "hello world"
  });
})

app.listen(config.port , () => {
  console.log(`listening on port ${config.port}`)
})