PtcRunner.Dotenv (PtcRunner v0.11.0)

Copy Markdown View Source

Loads environment variables from .env files.

Walks up from a starting directory to find the nearest .env file and sets variables that aren't already present in the environment.

Examples

# Load from nearest .env, only once per VM
PtcRunner.Dotenv.load()

Summary

Functions

Find the nearest .env file by walking up from dir.

Load environment variables from the nearest .env file.

Parse path as a .env file and set the variables it declares.

Functions

find_dotenv(dir)

@spec find_dotenv(String.t()) :: String.t() | nil

Find the nearest .env file by walking up from dir.

Returns the path to the first .env found, or nil if none exists up to the filesystem root.

load()

@spec load() :: :ok

Load environment variables from the nearest .env file.

Walks up from the current working directory looking for a .env file. Only sets variables that aren't already set (existing env vars take precedence). Safe to call multiple times — only loads once per VM.

load_file(path)

@spec load_file(String.t()) :: :ok

Parse path as a .env file and set the variables it declares.

Lines are KEY=VALUE; blank lines and # comments are ignored. Surrounding single or double quotes are stripped from the value. Existing environment variables are never overwritten.