Skip to content

std/os

Import with import std/os.

fn get(name: String): Maybe<String>

Process environment access.

os.get is available to package boot code for converting process state into explicit config or app values.

Return the process environment variable named name, or None when it is unset.

Optional environment values usually flow through Maybe.with_default:

port =
  os.get("PORT")
  |> Maybe.flat_map(String.to_int)
  |> Maybe.with_default(3000)

Required environment values can be converted to Result and allowed to fail boot explicitly:

database_url =
  os.get("DATABASE_URL")
  |> Result.from_maybe("DATABASE_URL is required")
  |> try