Dotenvy.env-exclamation-mark
env-exclamation-mark
, go back to Dotenvy module for more information.
Specs
Reads the given env variable
and converts its value to the given type
.
This function attempts to read value from a local data store of sourced values;
it will fall back to System.fetch_env/1
only if there is no locally stored variable.
This function may raise an error because type conversion is delegated to
Dotenvy.Transformer.to!/2
-- see its documentation for a list of supported types.
Examples
iex> env!("PORT", :integer)
5432
iex> env!("ENABLED", :boolean)
true
Specs
Reads an env variable and converts its output or returns a default value.
Use of env!/2
is usually recommended over env!/3
because it creates a stronger contract with
the environment (i.e. your app literally will not start if required env variables are missing)
but there are times where supplying default values is desirable, and the env!/3
function is
appropriate for those situations.
If the given variable
is set, its value is converted to
the given type
. The provided default
value is only used when the
variable is not set; the default
value is returned as-is, without conversion.
This allows greater control of the output.
This function may raise an error when the conversion is delegated to Dotenvy.Transformer.to!/2
-- see its documentation for a list of supported types.
This function attempts to read value from a local data store of sourced values;
it will fall back to System.fetch_env/1
.
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")
** (RuntimeError) Error converting HOST to string!: non-empty value required