> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# mergeWithEnv

> Merge configuration with prefix-matched environment variables.

[ref-substitutevars]: /docs/server-sdks/reference/typescript/agents/configuration/config-loader/substitute-vars

Merge the loaded configuration with environment variables whose names start
with a given prefix. Config file values take precedence over environment
variables -- env vars only fill in keys that are missing from the config.

Matching env var names are:

1. Stripped of the prefix
2. Lowercased
3. Split on `_` to produce a nested object path

For example, with prefix `SWML_`, `SWML_SERVER_PORT=3000` produces
`{ server: { port: "3000" } }`.

<Note>
  All values inherited from env vars are written as strings (Node returns
  `process.env` values as strings). Apply
  [`substituteVars()`][ref-substitutevars] to the result if you need type
  coercion.
</Note>

## **Parameters**

<ParamField path="envPrefix" type="string" default="'SWML_'" toc={true}>
  Prefix for environment variables to consider.
</ParamField>

## **Returns**

`Record<string, unknown>` -- the merged configuration (file + prefixed env
vars) with `${VAR}` substitution applied to file values.

## **Example**

```typescript {7}
import { ConfigLoader } from '@signalwire/sdk';

// Given config.json: { "server": { "host": "0.0.0.0" } }
// And env: SWML_SERVER_PORT=3000

const loader = new ConfigLoader('config.json');
const merged = loader.mergeWithEnv();
console.log(merged);
// { server: { host: "0.0.0.0", port: "3000" } }
```