Slide 28 of 37

Environment variables

proc main(): void {
	result := hive.env.get("DATABASE_URL")
	if result is Result.Ok(url) {
		echo "DATABASE_URL is {url}"
	} else if result is Result.Error(why) {
		echo "DATABASE_URL is not set: {why.message}"
	}
}
hive.env.get resolves a name in one order: the .env file beside the program, then the .env in the parent folder, then the OS environment — and answers with a Result, since a variable that was never set is an ordinary outcome rather than a crash. The .env file is read once, on the first get: blank lines and # comments are ignored, an export prefix is allowed and stripped, and a quoted value has its quotes removed.