[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/core](../../README) / [config](../README) / ConfigManager

# Class: ConfigManager

Defined in: [config/ConfigManager.ts:29](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L29)

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

```ts
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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L31)

#### Returns

`ConfigManager`

## Methods

### load()

> **load**(`namespace`, `values`): `void`

Defined in: [config/ConfigManager.ts:50](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L50)

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

```ts
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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L71)

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

```ts
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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L98)

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

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

***

### set()

> **set**(`path`, `value`): `void`

Defined in: [config/ConfigManager.ts:117](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L117)

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](#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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L148)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/config/ConfigManager.ts#L159)

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.
