Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current environment name

In Phoenix Framework, how can I get the current environment's name ?

I've already tried reading env variables with System.get_env("MIX_ENV"), but the value is not always set.

like image 470
Chris Avatar asked Jan 26 '16 09:01

Chris


People also ask

How do you check an active environment in Anaconda?

Create a new environment After creating your new environment, you can run conda env list to check your new environment. The environments created by Conda is always located in /Users/.../anaconda3/envs/ . You may change the default location by using the following command but it is not encouraged.

How do you find the conda environment path?

If you activate the environment you're interested in, you can find that answer in the environment variables. You can also run conda info --envs , and that will show the paths to all your environments. That should return the path you're looking for.

How do I know which environment Jupyter laptop is running?

Open the notebook in Jupyter Notebooks and look in the upper right corner of the screen. It should say, for example, "Python [env_name]" if the language is Python and it's using an environment called env_name.


2 Answers

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 
like image 128
Sheharyar Avatar answered Oct 01 '22 04:10

Sheharyar


You can use Mix.env/0:

iex(1)> Mix.env :dev 
like image 26
Chris Avatar answered Oct 01 '22 03:10

Chris