I defined a environment variable related to the guide-started, my mix.exs is
defmodule Basic.Mixfile do
use Mix.Project
def project do
[app: :basic,
version: "0.0.1",
elixir: "~> 0.13.0-dev",
deps: deps,
env: [
dev: [foo: "bar"] ] ]
end
# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[ applications: [],
mod: { Basic, [] } ]
end
# List all dependencies in the format:
#
# { :foobar, git: "https://github.com/elixir-lang/foobar.git", tag: "0.1" }
#
# Type `mix help deps` for more examples and options
defp deps do
[]
end
end
and then I start the project with iex -S mix or MIX_ENV=dev iex -S mix, I want to get the environment variable with :application.get_env(:basic, :foo) , it turned to :undefined; and use :application.get_all_env(:basic), it returned [included_applications: []], there is not the env variable. And my question is how should I get the environment value?
The :env must not be specified in project but inside the application one.
def application do
[ applications: [],
mod: { Basic, [] },
env: [foo: :bar] ]
end
Then you can access it as:
Application.get_env(:basic, :foo)
In this case, there is no support for specifying the environment for a particular MIX_ENV (like dev or prod). This is exactly why :env inside project is deprecated. Having two keys being named :env with different behaviour is recipe for confusion. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With