Phoenix application not picking up environment variable changes

Hi,

I am new to the Elixir and Pheonix world. I have been building an app to learn and so far it has been awesome and having lots of fun. One thing that I have come up against that I can not figure out is related to environment variables. I have a .env file that I source before I start phx.server. It has been working great until I change some of the values today. I am setting them in my config.ex like so:

config :days, paypal_host: System.get_env("PAYPAL_HOST")

and then calling it in my module like so:

@host Application.get_env(:days, :paypal_host)

I am sure it is my lack of understanding how the pheonix app is built but when I change the PAYPAL_HOST environment var I need to either remove the _build folder or make a change to my module for the change to be picked up.

Is this the normal process? Hopefully this makes sense and I can answer any questions.

Thank you and thank you for this community!

1 Like

config.exs is compile time configuration. for runtime configuration, you need to use runtime.exs introduced in elixir 1.11
https://hexdocs.pm/elixir/Config.html#module-config-runtime-exs

5 Likes

Ah! Ok - duh :man_facepalming: I am still getting used to the compile vs runtime stuff. I have been a Ruby developer for the past 14 years. Thank you so much! Just made some changes and it is working perfectly.

2 Likes

Additionally module attributes also are compile time (calling Application.get_env/2 in compile time is deprecated in favour of Application.compile_env/2).

1 Like