Godot 4 addon for loading .env files.
⚠️ .env
files should never be commited to source control, remember to add them to a.gitignore
file.
- Copy
addons
to the root of your project. - Activate the plugin by going to
Project -> Settings -> Plugins
, click enable forGD Env
.
By default the plugin will auto load the env file at res://.env
at project launch.
GDScript FileAccess.get_csv_line
is used to read the lines, read the docs on it to avoid possible parsing errors.
extends Node
func _ready() -> void:
# Optional, use only if current env should not be accesible anymore.
Env.clear()
var parse_result: Error = Env.parse("res://.env")
if parse_result != OK:
return
# Assume MY_KEY has been parsed, its value can be accessed either way:
# Env.get_key("MY_KEY")
# OS.get_environment("MY_KEY)
## Emitted when loaded envs are cleared.
signal cleared
## Emitted when new envs have been parsed.
signal parsed
## Clears last loaded keys.
func clear() -> void
## Loads env file.
func parse(file_path: String) -> Error
## Gets key from loaded env, returns "" if key is not found.
func get_key(key: String, default: String = "") -> String