Application Configuration
Learn how to configure your application in Elixir.
We'll cover the following
A limitation and its solution
Before we discuss upgrading production systems, we should cover application configuration. Most Elixir developers use config/config.exs
to configure their applications and dependencies, but remember that Mix loads config/config.exs
when building the release. That means environment variables or configuration files we read in config.exs
will be available while we build our release, but not in production.
To work around this limitation, many projects like Ecto and Phoenix started to support a special value called {:system, "env"}
to allow some dynamic configuration. The problem with this solution is that it works only for certain keys and only for certain applications. Fortunately, Ecto v2.1 and Phoenix v1.3 are moving to a more standardized approach. They’ll both move runtime configuration to inside the init
callback. Take the following example.
In earlier Ecto versions, if we wanted to dynamically configure the database URL Ecto connects to, we’d do so in our config/config.exs
, like this:
Get hands-on with 1400+ tech skills courses.