Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use envy with phoenix? #20

Open
webmstk opened this issue Apr 18, 2020 · 3 comments
Open

How do I use envy with phoenix? #20

webmstk opened this issue Apr 18, 2020 · 3 comments

Comments

@webmstk
Copy link

webmstk commented Apr 18, 2020

I placed section

    unless Mix.env() == :prod do
      Envy.auto_load()
    end

to lib/app/application.ex and it does not work (I have System.get_env("DB_USER", "postgres") in config/dev.exs)

@Narven
Copy link

Narven commented Sep 19, 2020

  1. create a .env file in the root of you App with content:
POSTGRES_USER=foobar
  1. open application.ex and add inside def start:
def start(_type, _args) do
  # ...
  unless Mix.env() == :prod do
    Envy.load([".env"])
  end
  # ...
end
  1. Any where on your application, just use:
<%= System.get_env("POSTGRES_USER") %>

It works on mine with

Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.10.4 (compiled with Erlang/OTP 23)
Phoenix Framework 1.5.4

@jckw
Copy link

jckw commented Jan 26, 2021

What about setting env vars in config.exs? Pretty sure config gets run before application start, so the env variables aren't set yet.

@J3RN
Copy link

J3RN commented Dec 27, 2021

In our codebase, we have Envy.load([".env"]) at the top of config files that require env vars from .env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants