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

# substituteVars

> Recursively substitute environment variables in any value.

[ref-interpolateenvvars]: /docs/server-sdks/reference/typescript/agents/configuration/config-loader/interpolate-env-vars

Recursively substitute `${VAR|default}` environment-variable references in any
value. Walks strings, objects, and arrays. After substitution, resulting
strings are coerced to:

* `true` / `false` when they equal `"true"` / `"false"` (case-insensitive)
* an integer when they match `/^\d+$/`
* a float when they match `/^\d+\.\d+$/`
* otherwise left as a string

<Note>
  For raw string interpolation without type coercion, use
  [`interpolateEnvVars()`][ref-interpolateenvvars] instead.
</Note>

## **Parameters**

<ParamField path="value" type="unknown" required={true} toc={true}>
  The value to process. Can be a string, object, array, or primitive.
</ParamField>

<ParamField path="maxDepth" type="number" default="10" toc={true}>
  Maximum recursion depth. Throws `Error("Maximum variable substitution depth
    exceeded")` when the limit is reached.
</ParamField>

## **Returns**

The input value with all environment variables substituted. Type depends on
the input and the coercion rules above.

## **Example**

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

const loader = new ConfigLoader();
const config = {
  port: '${PORT|8080}',
  debug: '${DEBUG|false}',
  name: '${SERVICE_NAME|my-service}',
};

const resolved = loader.substituteVars(config);
console.log(resolved);
// { port: 8080, debug: false, name: "my-service" }  (types coerced)
```