function loadConfig
Since 0.2.0
loadConfig(
runtime: IRuntimeServices,
): Promise<IConfig>

Builds an immutable configuration snapshot from the environment.

Sources are merged (runtime environment over .env files), ${NAME} references are expanded unless disabled, and a supplied schema validates and coerces the result — in that order, so references observe final values and the schema sees expanded ones.

Supplying ConfigPluginOptions.instance short-circuits all of that and returns the given snapshot, which is what lets an application load configuration once and hand the same object to the plugin.

Examples

Reading configuration before an application exists

import { createRuntimeServices } from '@setu-ts/runtime';
import { loadConfig } from '@setu-ts/config-plugin';

const config = await loadConfig(createRuntimeServices(), {
  envFilePath: ['.env.local', '.env'],
});
const port = config.get<number>('PORT', { default: 3000 });

Parameters

runtime: IRuntimeServices

Runtime services providing env and, for files, fs

optional
options: ConfigPluginOptions

Loading, expansion, validation, and instance options

Return Type

Promise<IConfig>

The configuration snapshot

Throws

Error

If envFilePath is set and the runtime has no filesystem, if a configured file cannot be read, or if validation rejects the result. Setting envFileOptional narrows the middle case: an ABSENT path is then skipped, while a path that exists and cannot be read still throws

Usage

import { loadConfig } from "config-plugin/src/index.ts";