Supply configuration values directly in code Core
StaticBind injects configuration values from an in-memory object. Use it when you need programmatic overrides for test fixtures, feature flags resolved at startup, or values derived from other runtime state.
Steps
1. Pass a StaticBind to ConfigBound.createConfig:
import { ConfigBound, configItem, configSection } from "@config-bound/config-bound";
import { StaticBind } from "@config-bound/config-bound";
import { z } from "zod";
const config = await ConfigBound.createConfig(
{
port: configItem<number>({
validator: z.number().int().min(1).max(65535)
}),
database: configSection({
host: configItem<string>({
validator: z.hostname()
})
})
},
{
binds: [
new StaticBind({
port: 8080,
database: { host: "db.local" }
})
]
}
);2. Values can be nested objects or flat dot-path keys. Both work:
new StaticBind({
port: 8080, // nested key
"database.host": "db.local" // flat dot-path key
})When a path resolves in both nested and flat forms, the nested value wins. If a nested value is null, resolution falls back to the flat key for that path. The StaticBind treats explicit null anywhere as unset.
StaticBind isn't the same as default
configItem({ default }) is a schema-level fallback. StaticBind participates in bind priority. It can be overridden by higher-priority binds, and it overrides lower-priority ones.
Use default when the value is a fixed constant that belongs to the schema. Use StaticBind when ConfigBound resolves the value at runtime and needs to interact with the bind chain.
Sensitive values
Don't hardcode secrets as literals in source files. StaticBind is fine for sensitive values as long as they're resolved at runtime—fetched from an upstream process—and passed in as variables, not string literals that end up in version control.
Related
StaticBindAPI reference- Use EnvVarBind - read config from environment variables
- Use FileBind - read config from a file