Skip to main content
zerotal

Documentation


Documentation / @zerotal/core / config / ConfigManager

Class: ConfigManager

Defined in: config/ConfigManager.ts:29

The runtime configuration store — holds every loaded config namespace and serves dot-path reads and writes.

Populated from the config/*.ts files during onBooting() by a ServiceProvider, then bound in the container under config. Application code rarely touches this class directly; it reads through the Config facade or the config() helper, both of which delegate here.

Example

import { config } from "@zerotal/core";
import { Config } from "@zerotal/core/facades";

// Typed dot-path access (via the config() helper):
const name = config("app.name");     // string
const port = config("app.port");     // number

// Or through the facade:
const url = Config.get("app.url", "http://localhost:3000");

Constructors

Constructor

new ConfigManager(): ConfigManager

Defined in: config/ConfigManager.ts:31

Returns

ConfigManager

Methods

load()

load(namespace, values): void

Defined in: config/ConfigManager.ts:50

Merge a config namespace into the store, replacing any existing value under the same key. Called by ConfigProvider during onBooting().

Parameters

namespace

string

Top-level namespace key (the config filename, e.g. app).

values

Record<string, unknown>

The namespace's config object.

Returns

void

Example

config.load('app', { name: 'Zerotal', env: 'production' });
config.load('database', { url: 'postgres://localhost/mydb' });

get()

get<T>(path, fallback?): T

Defined in: config/ConfigManager.ts:71

Get a config value by dot-notation path, returning fallback when the path resolves to null/undefined or does not exist.

Type Parameters

T

T = unknown

Parameters

path

string

Dot-notation path, e.g. app.name.

fallback?

T

Value returned when the path is missing.

Returns

T

The stored value, or fallback when unset.

Example

config.get('app.name')                      // 'Zerotal'
config.get('database.connections.postgres') // { url: '...' }
config.get('app.missing', 'default')        // 'default'

require()

require<T>(path): T

Defined in: config/ConfigManager.ts:98

Get a config value, throwing when it is null or undefined. Use for required config that the app cannot start without.

Type Parameters

T

T = unknown

Parameters

path

string

Dot-notation path, e.g. app.key.

Returns

T

The stored value (guaranteed present).

Throws

When the path resolves to undefined or null.

Example

config.require('app.key') // throws if APP_KEY is not set

set()

set(path, value): void

Defined in: config/ConfigManager.ts:117

Set a config value at a dot-path at runtime, creating intermediate objects as needed. Intended for tests or dynamic overrides; in production prefer loading config files via ConfigManager.load.

Parameters

path

string

Dot-notation path to write, e.g. app.debug.

value

unknown

The value to store.

Returns

void


has()

has(path): boolean

Defined in: config/ConfigManager.ts:148

Check whether a config path has a value set (i.e. get(path) is not undefined).

Parameters

path

string

Dot-notation path to test.

Returns

boolean

true when a value exists at the path.


all()

all(): Record<string, unknown>

Defined in: config/ConfigManager.ts:159

Return a shallow copy of all loaded config namespaces. Useful for debugging.

Returns

Record<string, unknown>

A new object mapping each namespace to its config value. The copy is shallow — nested namespace objects are shared, not cloned.