Link Search Menu Expand Document

Env

Table of contents

  1. Env
    1. Env.get(string)
    2. Env.set(string, value)

Env

To make use of the Env module an import is required.

import Env;

Env.get(string)

Get an environment variable. .get() will return a string if a valid environment variable is found otherwise nil.

Env.get("bad key!"); // nil
Env.get("valid key"); // "value"

Env.set(string, value)

Change or add an environment variable. You can clear an environment variable by passing a nil value. When setting an environment variable the key must be a string and the value must be either a string or nil. Returns a Result type and on success will unwrap to nil.

Env.set("key", "test");
Env.set("key", nil); // Remove env var
Env.set("key", 10); // set() arguments must be a string or nil.

This site uses Just The Docs, with modifications.