Nex.Env (nex_core v0.4.3)

Copy Markdown

Environment variable management.

Loads from .env files and system environment.

Summary

Functions

Returns the current environment name as a string. Uses Mix.env() when available (dev/test), falls back to MIX_ENV env var, then defaults to "prod" - safe for compiled releases.

Detects project root directory. In dev/test (Mix available): walks up from _build app path. In prod release (no Mix): uses the directory of the running executable or cwd.

Get environment variable with optional default

Get required environment variable (raises if missing)

Get environment variable as boolean

Get environment variable as integer

Initialize environment from .env files.

Functions

current_env(opts \\ [])

Returns the current environment name as a string. Uses Mix.env() when available (dev/test), falls back to MIX_ENV env var, then defaults to "prod" - safe for compiled releases.

Can be overridden for testing with :mix_env and :system_env options.

detect_project_root(opts \\ [])

Detects project root directory. In dev/test (Mix available): walks up from _build app path. In prod release (no Mix): uses the directory of the running executable or cwd.

Can be overridden for testing with :mix_project_path and :progname options.

get(key, default \\ nil)

Get environment variable with optional default

get!(key)

Get required environment variable (raises if missing)

get_boolean(key, default)

Get environment variable as boolean

get_integer(key, default)

Get environment variable as integer

init(opts \\ [])

Initialize environment from .env files.

Options:

  • :env - Override the environment name (default: auto-detected)
  • :project_root - Override the project root path (default: auto-detected)