dot_env/env

Functions

pub fn get(key: String) -> Result(String, String)

Get an environment variable (supports both Erlang and JavaScript targets)

Example:

import dot_env/env
import gleam/io
import gleam/result

env.get("FOO")
|> result.unwrap("NOT SET")
|> io.println
pub fn get_bool(key: String) -> Result(Bool, String)

Get an environment variable as a boolean

pub fn get_bool_or(key: String, default: Bool) -> Bool

Get an environment variable as a boolean or return a default value if it is not set

pub fn get_int(key: String) -> Result(Int, String)

Get an environment variable as an integer

pub fn get_int_or(key: String, default: Int) -> Int

Get an environment variable as an integer or return a default value if it is not set

pub fn get_or(key: String, default: String) -> String

Get an environment variable or return a default value if it is not set

pub fn get_then(
  key: String,
  f: fn(String) -> Result(a, String),
) -> Result(a, String)

An alternative implementation of get that allows for chaining using use

pub fn set(key: String, value: String) -> Result(Nil, String)

Set an environment variable (supports both Erlang and JavaScript targets)

Example:

import dot_env/env

env.set("FOO", "my value")
Search Document