Skip to content

env

This content is for v1.0. Switch to the latest version for up-to-date documentation.

The env namespace provides straightforward access to process environment variables. No import is required.


FunctionSignatureReturn TypeDescription
env.getenv.get(key, default = null)string | nullRetrieves value of an environment variable.
env.setenv.set(key, val)boolSets 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.
env.path_addenv.path_add(dir)boolPrepends or appends a directory to system PATH.

Retrieves the value of environment variable key:

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

Sets an environment variable for the current process:

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

if (env.has("DEBUG")) {
print("Debug mode enabled.");
}

Adds a new directory to the system executable search PATH:

env.path_add("C:/rayquiro/bin");