Get current environment name

Mix.env() doesn’t work in production or other environments where you use compiled releases (built using Exrm / Distillery) or when Mix just isn’t available.


The solution is to specify it in your config/config.exs file:

config :your_app, env: Mix.env()

You can then get the environment atom in your application like this:

Application.get_env(:your_app, :env)
#=> :prod

Update (March 2022):

Recent versions of Elixir (v1.13.x+) recommend using config_env() instead of Mix.env(), so do this:

config :your_app, env: config_env()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)