Environment
Access environment variables from both process environment and .env files.
Automatic .env loading
Section titled “Automatic .env loading”ngn automatically loads .env files at startup in this order (later overrides earlier):
.env- Base configuration.env.{mode}- Mode-specific (production, development, test).env.local- Local overrides (should be gitignored)
The mode is determined by the NGN_MODE environment variable (default: development).
Direct key access
Section titled “Direct key access”Access environment variables directly as properties. Returns Maybe<string>:
// Direct property accessconst db = env.DATABASE_URL ?? "localhost"const port = env.PORT ?? "3000"
// With pattern matchingmatch (env.API_KEY) { Value(key) => print("Key: ${key}"), Null => panic("API_KEY is required!"),}Get by dynamic key. Returns Maybe<string>.
const key = "DATABASE_URL"const value = env.get(key) ?? "default"Check if a variable exists. Returns bool.
if (env.has("DEBUG")) { print("Debug mode enabled")}