Dotenvy.env
You're seeing just the function
env
, go back to Dotenvy module for more information.
Specs
Reads a system environment variable and converts its output or returns a default value.
If the given system environment variable
is set, its value is converted to
the given type
. The default
value is only used when the system environment
variable is not set; the default
value is retur as-is, without conversion.
This allows greater control of the output.
Although this relies on System.fetch_env/1
, it may still raise an error
if an unsupported type
is provided or if non-empty values are required.
The conversion is delegated to Dotenvy.Transformer.to/2
-- see its documentation
for a list of supported types.
Examples
iex> env("PORT", :integer, 5432)
5433
iex> env("NOT_SET", :boolean, %{not: "converted"})
%{not: "converted"}
iex> System.put_env("HOST", "")
iex> env("HOST", :string!, "localhost")
** (Dotenvy.Transformer.Error) non-empty value required