bkeepers / dotenv

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

does dotenv supports multiple .env files for non-rail app?

tchiaspko opened this issue · comments

From the "What other .env* files can I use?" of https://www.rubydoc.info/gems/dotenv-rails/2.7.4, it seems the .env.local will override .env for an rails app

Is there something similar for non-rail app?

I wanted to use .env which for the project(rspec) I check into git and .env.local which contains personal ENV vars such as username/password that I don't want to check into git.

Steps to reproduce

In Gemfile,

gem 'dotenv'

In spec/spec_helper.rb

require 'dotenv/load'
Dotenv.load(".env.local", ".env")

Expected behavior

Same variable defined in .env.local should override the same variable in .env

Actual behavior

.env always wins if the same variable is defined in both .env and .env.local
It doesn't matter which order i call the load function
i.e. I have tried these and they give the same result
Dotenv.load(".env.local", ".env")
Dotenv.load(".env", ".env.local")

System configuration

dotenv version:
dotenv (2.7.4)
Rails version:
None

Ruby version:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin18]

👋 The issue you're experiencing is because of your require "dotenv/load" which loads the library and immediately calls Dotenv.load. You can achieve what you're looking for with the following:

require "dotenv"
Dotenv.load(".env.local", ".env")
commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.