Environment variables

Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?

config :myapp, :enable, value: “${enable}”

I don’t remember there’s such thing like ${} in Elixir, you might mean #{} for string interpolation?

You can use System.get_env("enable") to get environment variable in your dev.exs file.

Hi chensan,
Thanks for help.
seen like this , currently i am keep trying.

That post is using Exrm for building OTP release, that’s why it’s using ${}, also exrm is deprecated now. Since you’re configurating your dev.exs, there’s no need to use exrm, just use System.get_env.


Check out this guide Kubernetes Native Phoenix Apps.

I’ve had to adapt it a little to my umbrella use case but is really good and up to date.

Hi, @sen!
For using environment variables you can create a .env file anywhere in your project folder, I prefer to create it in project_name/config folder, with a content like here:

export FILE_FOLDER='/home/username/file_folder'
export FIRST_VARIABLE='some_var'

after saving file, source it using source config/.env from project directory, then u can use those variables in your project using commmand:
Good luck!

IMPORTANT: don’t add spaces before and after equal sign.

1 Like

I am very strongly interested in a blog post about this, if you decide to write one!

Thanks all.
I am doing like this, when i build and run docker after, can get the value in HomeController test.
But endpoint and route nothing to change, cant get the value.
I want to enable/disable plugin. if true will enable that plugin.
Anyone know the reason? if cant doing like this, i will change other way.

config :myapp, :enable, value: “${ENABLE}”

if Application.get_env(:myapp, :enable)[:value] do
disable/enable plugin…