How to get current enviroment name in Phoenix Elixir
Today I've Learned postMost straight forward way is like this:
if System.get_env("MIX_ENV") == "dev" do
# ...
end
…or
Mix.env == :dev
But the problem is that if you are deploying with Exrm or Distillery then Mix doesn’t work in production source.
This may not be an issue if you use Docker image that includes Mix (which depends on usecase may/may not be good enough for you) but in general it’s recommended to do following (solution from SO user Sheharyar :
Create custom config/config.exs
:
# config/config.exs
config :your_app, env: Mix.env
Then you can get environment:
Application.get_env(:your_app, :env)
#=> :prod
Entire blog website and all the articles can be forked from this Github Repo