Hyperlinkv0.8.0-beta.28

ConfigProvider

ConfigProvider.fromDotEnvContentsfunctioneffect/ConfigProvider.ts:967
(
  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)
ConfigProvidersfromEnvfromDotEnv
export function fromDotEnvContents(lines: string, options?: {
  readonly expandVariables?: boolean | undefined
  readonly preserveEmptyStrings?: boolean | undefined
}): ConfigProvider {
  let env = parseDotEnvContents(lines)
  if (options?.expandVariables) {
    env = dotEnvExpand(env)
  }
  return fromEnv({ env, preserveEmptyStrings: options?.preserveEmptyStrings })
}
Referenced by 1 symbols