Skip to content

Environment

Access environment variables from both process environment and .env files.

ngn automatically loads .env files at startup in this order (later overrides earlier):

  1. .env - Base configuration
  2. .env.{mode} - Mode-specific (production, development, test)
  3. .env.local - Local overrides (should be gitignored)

The mode is determined by the NGN_MODE environment variable (default: development).

Access environment variables directly as properties. Returns Maybe<string>:

// Direct property access
const db = env.DATABASE_URL ?? "localhost"
const port = env.PORT ?? "3000"
// With pattern matching
match (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")
}