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.
Quick Reference
Section titled “Quick Reference”| Function | Signature | Return Type | Description |
|---|---|---|---|
env.get | env.get(key, default) | string | null | Retrieves value of an environment variable. |
env.set | env.set(key, val) | void | Sets or updates an environment variable. |
env.has | env.has(key) | bool | Checks if an environment variable is defined. |
env.all | env.all() | object | Returns all environment variables as a key-value map. |
Detailed Methods
Section titled “Detailed Methods”env.get(key, default_val = null)
Section titled “env.get(key, default_val = null)”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!");}env.set(key, val)
Section titled “env.set(key, val)”Sets an environment variable for the current process and its spawned children:
env.set("APP_ENV", "production");print("Mode: " + env.get("APP_ENV"));env.has(key)
Section titled “env.has(key)”Returns true if the environment variable exists, otherwise false:
if (env.has("CI")) { print("Running inside Continuous Integration environment.");}env.all()
Section titled “env.all()”Dumps all current environment variables into a RayQuiro object:
var vars = env.all();print("Home Directory: " + vars["HOME"]);print("Current Path: " + vars["PATH"]);