Env

Config & IO

Process environment variables for the BEAM target.

Use load / loadFrom with Env.Decode to read a .env file and decode it into your own type. Existing process variables are not overridden.

parse is implemented with Parser.

Values

get

get : String -> Maybe String

Look up an environment variable by name.

Returns Nothing when the variable is unset.

Examples

Env.get "PORT"

set

set : String -> String -> ()

Set an environment variable in the current OS process.

Examples

Env.set "PORT" "3000"

unset

unset : String -> ()

Unset an environment variable.

Examples

Env.unset "PORT"

all

all : Dict String String

All environment variables as a dictionary.

Examples

Env.all

decode

decode : Decoder a -> Result String a

Decode the current process environment (no file read).

Examples

Env.decode configDecoder

parse

parse : String -> Dict String String

Parse dotenv text into a dictionary without changing the process environment.

Examples

Env.parse "PORT=3000\n"

load

load : Decoder a -> Result String a

Read .env from the working directory, merge unset keys into the process environment, then decode with the given decoder.

Examples

Env.load configDecoder

loadFrom

loadFrom : String -> Decoder a -> Result String a

Like load, but reads the given file path instead of .env.

Examples

Env.loadFrom ".env.local" configDecoder