(name?: string): Config<number>Creates a config for a port number (integer in 1–65535).
When to use
Use to read network port settings that must be valid port numbers.
Details
Shortcut for Config.schema(Config.Port, name).
Example (Reading a port)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const port = yield* Config.port("PORT")
console.log(port)
})
const provider = ConfigProvider.fromEnv({
env: {
PORT: "8080"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output: 8080export function function port(
name?: string
): Config<number>
Creates a config for a port number (integer in 1–65535).
When to use
Use to read network port settings that must be valid port numbers.
Details
Shortcut for Config.schema(Config.Port, name).
Example (Reading a port)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const port = yield* Config.port("PORT")
console.log(port)
})
const provider = ConfigProvider.fromEnv({
env: {
PORT: "8080"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output: 8080
port(name: string | undefinedname?: string) {
return function schema<T>(
codec: Schema.ConstraintCodec<T, unknown>,
path?: string | ConfigProvider.Path
): Config<T>
Creates a Config<T> from a Schema.Codec.
When to use
Use when you need to read structured or schema-validated configuration.
Details
The optional path sets the local path segment(s) for the config lookup.
It is appended to the logical path prefix accumulated from outer
nested
calls. Pass a single string for a flat key or an array for
nested paths.
Convenience constructors such as string, number, and boolean delegate
to this API.
The codec is used to decode the raw StringTree produced by the provider
into T. Schema validation errors are wrapped in ConfigError.
Example (Reading a structured config)
import { Config, ConfigProvider, Effect, Schema } from "effect"
const DbConfig = Config.schema(
Schema.Struct({
host: Schema.String,
port: Schema.Int
}),
"db"
)
const provider = ConfigProvider.fromUnknown({
db: { host: "localhost", port: 5432 }
})
// Effect.runSync(DbConfig.parse(provider))
// { host: "localhost", port: 5432 }
schema(const Port: Schema.Intconst Port: {
Rebuild: Int;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<number, readonly []>) => Schema.Int;
annotateKey: (annotations: Schema.Annotations.Key<number>) => Schema.Int;
check: (checks_0: SchemaAST.Check<number>, ...checks: Array<SchemaAST.Check<number>>) => Schema.Int;
rebuild: (ast: SchemaAST.Number) => Schema.Int;
make: (input: number, options?: MakeOptions) => number;
makeOption: (input: number, options?: MakeOptions) => Option_.Option<number>;
makeEffect: (input: number, options?: MakeOptions) => Effect.Effect<number, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Schema for port numbers (integers in 1–65535).
When to use
Use when you need the reusable port schema value for Config.schema with
custom paths.
Port, name: string | undefinedname)
}