Environment Functions
Read, set, and manage environment variables with .env file support.
Environment Variables
getenv(name)
Get the value of an environment variable.
Parameters
name : String - The environment variable name
Returns
String? - The value or null if not set
db_url = getenv("DATABASE_URL")
port = getenv("PORT") ?? "3000"
hasenv(name)
Check if an environment variable is set.
Returns
Bool - true if the variable exists
if hasenv("DEBUG") {
println("Debug mode enabled")
}
.env File Support
.env and .env.{APP_ENV} in the application directory are auto-loaded once at server startup — no Soli-level call is needed.
Common Patterns
Configuration Management
# `.env` and `.env.{APP_ENV}` are auto-loaded at server startup —
# no `dotenv` call needed.
# Configuration with defaults
config = {
"database_url": getenv("DATABASE_URL") ?? "postgres://localhost/dev",
"port": int(getenv("PORT") ?? "3000"),
"debug": getenv("DEBUG") == "true",
"secret_key": getenv("SECRET_KEY")
}
# Validate required config
if !config["secret_key"]
panic("SECRET_KEY environment variable is required")
end