Skip to content

Environment Variables (std.env)

Query and modify process environment variables or locate system temporary folders:


import std.env
// Read an environment variable (returns Nil if not found)
let port = env.get("PORT")
if port == Nil {
port = "8080"
}
// Set or replace an environment variable for child processes
env.set("APP_ENV", "production")
// Retrieve the system temporary directory path
let tmp_dir = env.temp()
println($"Temporary Directory: {tmp_dir}")

Method Arguments Returns Description
env.get key: String String | Nil Retrieves the value of an environment variable, or Nil if unset.
env.set key: String, value: String Nil Sets or overwrites an environment variable in the current process scope.
env.remove key: String Nil Deletes an environment variable from the current process scope.
env.vars None Formula Returns a key-value formula map of all currently exported environment variables.
env.temp None String Returns the absolute path to the system temporary folder.