bkeepers / dotenv

A Ruby gem to load environment variables from `.env`.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refresh ENV during runtime

albertski opened this issue · comments

I created a console command that updates my .env file, but also in the same runtime, it accesses ENV. The problem is that it reads the old values, even though I updated the .env file. Is there a way to refresh the ENV during runtime so it gets the latest values?

I tried Dotenv.load('.env') but it didn't help.

.env

FOOBAR=hello

ruby.rb

puts ENV['FOOBAR'] # Prints "hello"
EnvFile.update_variable('.env', 'FOOBAR', "How are you?")
Dotenv.load('.env')
puts ENV['FOOBAR'] # Prints "hello" even though looking in .env it has the new value "How are you?"

Use Dotenv.overload('.env')

Thanks for your help. That worked perfectly.