Loads environment variables from .env into ENV in development
open sourceMITfree
dotenv is the Ruby gem that loads environment variables from a .env file into ENV when an app boots, for development and test machines where setting them by hand isn't practical. It loads automatically in Ruby on Rails through dotenv-rails, and in Sinatra or plain Ruby with require 'dotenv/load', reading several files in order without overwriting variables that are already set. Since 3.0 it restores ENV after each Rails test. It supports multi-line values, variable and command substitution, Rake tasks, and a dotenv command that runs a script with the variables loaded or writes a template of a .env file. It is MIT licensed.
Problems it solves
- keep API keys out of my Ruby code and load them from a file in development
- set environment variables for my Rails app locally without exporting them in my shell
- tests that change ENV leak into other tests
Features
- loads .env files into ENV at boot
- automatic loading in Rails, with per-environment files
- restores ENV after each test
- variable and command substitution, multi-line values
- dotenv command to run scripts with the variables loaded
- creates a template of a .env file
