Skip to content

Env Class

The Env class manages environment variables and .env files.

env = new Env()

env.loadEnv()

Load .env file from the current directory. Called automatically on init().

env.loadEnv()

env.loadFile(cPath)

Load environment variables from a specific file.

env.loadFile("/etc/myapp/env")

env.getVar(cKey)

Get an environment variable value. Returns empty string if not found.

dbUrl = env.getVar("DATABASE_URL")

env.getOr(cKey, cDefault)

Get an environment variable with a default fallback.

port = env.getVar("PORT")
if port = "" port = "3000" ok

# Or more concisely:
port = env.getOr("PORT", "3000")

env.setVar(cKey, cValue)

Set an environment variable.

env.setVar("APP_ENV", "production")