Interpolating environment variables

Let's start by looking at the way we set the database configuration in the elixir_drip umbrella app while developing locally:

$ cat apps/elixir_drip/config/dev.exsuse Mix.Configconfig :elixir_drip, ElixirDrip.Repo,  adapter: Ecto.Adapters.Postgres,  username: System.get_env("DB_USER"),  password: System.get_env("DB_PASS"),  database: System.get_env("DB_NAME"),  hostname: System.get_env("DB_HOST"),  port: System.get_env("DB_PORT"),  pool_size: 10

All these Mix configuration entries are evaluated at runtime, so when we run the application with mix or mix phx.server, we know all those entries will be set according to the existing DB_* environment variables. If one of those environment variables doesn't exist, Mix ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.