Why?
We needed a way of checking that environment variables were defined and improving the developer experience when they are not.
What?
envar is our solution to a very specific problem:
the developer experience when a required environment variable is undefined.
How?
Installation
Install the package
by adding envar to your list of dependencies in your mix.exs file:
def deps do
[
{:envar, "~> 1.0.1"}
]
end
Usage
In your code, when you need to retrieve an environment variable, use the following:
DATABASE_URL = Envar.get("DATABASE_URL")
Or if you need to check that a variable is set, use:
if Envar.is_set?("Heroku") do
# do stuff on Heroku
end
For more detail, please see docs: https://hexdocs.pm/envar/api-reference.html
Context
We created this module after doing
a search of the Elixir (Hex.pm)
ecosystem,
see:
dwyl/learn-environment-variables/issues/18
There are several modules available,
we wanted something very basic/specific to our needs.
We don't expect anyone else to use this;
it's Open Source
because that's just what we do:
/manifesto.md#open-source-always