(
lines: string,
options?: {
readonly expandVariables?: boolean | undefined
readonly preserveEmptyStrings?: boolean | undefined
}
): ConfigProviderCreates a ConfigProvider by parsing the string contents of a .env file.
When to use
Use when you already have the .env contents as a string, such as contents
fetched from a remote store or embedded in a test.
Details
Supports export prefixes, single/double/backtick quoting, inline comments,
and escaped newlines. Variable expansion (for example, ${VAR}) is disabled
by default; enable with { expandVariables: true }.
Literal empty strings are treated as missing values when loaded as values by
default. Pass { preserveEmptyStrings: true } to keep empty strings as
explicit values. Child discovery still reflects the keys present in the
parsed .env source.
Parsing is based on the dotenv / dotenv-expand algorithm.
Internally delegates to fromEnv with the parsed key-value pairs.
Example (Parsing .env contents)
import { ConfigProvider } from "effect"
const contents = `
HOST=localhost
PORT=3000
# this is a comment
`
const provider = ConfigProvider.fromDotEnvContents(contents)export function function fromDotEnvContents(
lines: string,
options?: {
readonly expandVariables?: boolean | undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
): ConfigProvider
Creates a ConfigProvider by parsing the string contents of a .env file.
When to use
Use when you already have the .env contents as a string, such as contents
fetched from a remote store or embedded in a test.
Details
Supports export prefixes, single/double/backtick quoting, inline comments,
and escaped newlines. Variable expansion (for example, ${VAR}) is disabled
by default; enable with { expandVariables: true }.
Literal empty strings are treated as missing values when loaded as values by
default. Pass { preserveEmptyStrings: true } to keep empty strings as
explicit values. Child discovery still reflects the keys present in the
parsed .env source.
Parsing is based on the dotenv / dotenv-expand algorithm.
Internally delegates to
fromEnv
with the parsed key-value pairs.
Example (Parsing .env contents)
import { ConfigProvider } from "effect"
const contents = `
HOST=localhost
PORT=3000
# this is a comment
`
const provider = ConfigProvider.fromDotEnvContents(contents)
fromDotEnvContents(lines: stringlines: string, options: | {
readonly expandVariables?:
| boolean
| undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
| undefined
options?: {
readonly expandVariables?: boolean | undefinedexpandVariables?: boolean | undefined
readonly preserveEmptyStrings?: boolean | undefinedpreserveEmptyStrings?: boolean | undefined
}): ConfigProvider {
let let env: Record<string, string>env = function parseDotEnvContents(
lines: string
): Record<string, string>
parseDotEnvContents(lines: stringlines)
if (options: | {
readonly expandVariables?:
| boolean
| undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
| undefined
options?.expandVariables?: boolean | undefinedexpandVariables) {
let env: Record<string, string>env = function dotEnvExpand(
parsed: Record<string, string>
): Record<string, string>
dotEnvExpand(let env: Record<string, string>env)
}
return function fromEnv(options?: {
readonly env?:
| Record<string, string>
| undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}): ConfigProvider
Creates a ConfigProvider backed by environment variables.
When to use
Use to read configuration from process.env, which is the default when no
provider is explicitly set, or pass a custom env record for testing or
non-Node runtimes.
Details
Path segments are joined with _ for direct lookup, and env var names are
also split on _ to build a trie for child key discovery. This means
DATABASE_HOST=localhost is accessible at both path ["DATABASE_HOST"]
and ["DATABASE", "HOST"]. If all immediate children of a trie node have
purely numeric names, the node is reported as an Array; otherwise as a
Record.
The default environment merges process.env and import.meta.env (when
available). Override by passing { env: { ... } }.
Literal empty strings are treated as missing values when loaded as values by
default. Pass { preserveEmptyStrings: true } to keep empty strings as
explicit values. Child discovery still reflects the environment variable
names present in the source.
Never fails with SourceError — all lookups are synchronous.
Example (Reading from a custom env record)
import { Config, ConfigProvider, Effect } from "effect"
const provider = ConfigProvider.fromEnv({
env: {
DATABASE_HOST: "localhost",
DATABASE_PORT: "5432"
}
})
const host = Config.string("HOST").parse(
provider.pipe(ConfigProvider.nested("DATABASE"))
)
// Effect.runSync(host) // "localhost"
fromEnv({ env?: Record<string, string> | undefinedenv, preserveEmptyStrings?: boolean | undefinedpreserveEmptyStrings: options: | {
readonly expandVariables?:
| boolean
| undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
| undefined
options?.preserveEmptyStrings?: boolean | undefinedpreserveEmptyStrings })
}