An application environment is an in-memory key-value store associated with an OTP application. Atom keys map to Elixir terms, and configuration can be loaded from Elixir scripts before the application starts. section 11.4
Configuring an HTTP port
Read TODO_HTTP_PORT at runtime, default to 5454, convert it to an integer, and store it as :http_port for :todo. Retrieve it with Application.fetch_env!(:todo, :http_port); use Application.get_env/3 when a default is preferable. section 11.4.1
Keep application, Mix, and OS environments distinct. Mix-specific configuration can select different OS variables and defaults, allowing development and test processes to use separate ports or database folders. section 11.4.2
Listing 11.14 Configuring the HTTP port (todo_env/config/runtime.exs)
import Config #1
http_port = System.get_env("TODO_HTTP_PORT", "5454") #2
config :todo, http_port: String.to_integer(http_port) #3
Shows the runtime configuration script that reads an OS variable and writes the converted port into the application environment. section 11.4.1
Prefer runtime.exs for externally supplied settings. config.exs runs before compilation, so it reads values from the build machine; libraries should generally accept parameters as function arguments instead. section 11.4.3
