Config
Build and combine Config values, supply defaults, and validate inputs.
Read more
Cloud-native applications are configured from the outside: ports, hostnames,
feature flags, and secrets all arrive through environment variables, .env
files, or mounted config volumes. Effect models configuration declaratively. You
describe what you need with a Config, and a ConfigProvider decides where
the raw values come from. The result is configuration that is typed, validated,
and trivially mockable in tests.
There are three pieces to understand:
Config<T> — a recipe for extracting and validating a value of type T.
A Config is itself an Effect, so you yield* it inside Effect.gen.ConfigProvider — the backing data source. The default reads from
environment variables, but you can swap in JSON, a .env file, or an
in-memory map.Redacted — a wrapper for secrets that keeps sensitive values out of logs
and error output.import { Config, Effect } from "effect"
const program = Effect.gen(function* () { // Each Config reads and validates one value from the current ConfigProvider const host = yield* Config.string("HOST") const port = yield* Config.port("PORT") // validated integer in 1–65535 yield* Effect.log(`Listening on ${host}:${port}`)})
// With no provider specified, Config reads from process.env by default:// HOST=localhost PORT=8080 node app.jsEffect.runFork(program)Because a Config resolves the current ConfigProvider from context, the
same program runs unchanged against environment variables in production and a
fixed map in tests — you only swap the provider.