Skip to content

env

This content is for v0.2.1. Switch to the latest version for up-to-date documentation.

The env namespace provides straightforward access to process environment variables.


FunctionSignatureReturn TypeDescription
env.getenv.get(key, default)string | nullRetrieves value of an environment variable.
env.setenv.set(key, val)voidSets or updates an environment variable.
env.hasenv.has(key)boolChecks if an environment variable is defined.
env.allenv.all()objectReturns all environment variables as a key-value map.

Retrieves the value of environment variable key. If the variable is not set, returns default_val (or null if not specified):

var port = env.get("PORT", "8080");
var api_key = env.get("API_SECRET");
if (api_key == null) {
print("Warning: API_SECRET is not configured!");
}

Sets an environment variable for the current process and its spawned children:

env.set("APP_ENV", "production");
print("Mode: " + env.get("APP_ENV"));

Returns true if the environment variable exists, otherwise false:

if (env.has("CI")) {
print("Running inside Continuous Integration environment.");
}

Dumps all current environment variables into a RayQuiro object:

var vars = env.all();
print("Home Directory: " + vars["HOME"]);
print("Current Path: " + vars["PATH"]);