Configuring Local Development Environment with dotenv
Learn about setting up the local development environment using dotenv for our Rails application.
What is dotenv?
The dotenv merges the existing UNIX environment with a set of key/value pairs stored in files. These files are named for the Rails environment they apply to, so .env.development
is used to store development environment variables, and .env.test
for test. Storing configuration keys and values in files means we avoid having to document what variables a developer must set and how to get the right value. Using dotenv means that our app can still access its runtime information from ENV
, so our code won’t be littered with checks for the Rails environment.
Our development and test runtime configuration values aren’t actual secrets, so we can safely check them into version control. We also won’t allow dotenv to run in production, so there’s no chance of files containing secrets creeping into our app and being used. This also has the added benefit of pushing more consistency into our developer workflow. There’s really no reason developers should have different Postgres configurations, and putting the credentials inside files checked into version control makes being consistent much easier.
Get hands-on with 1400+ tech skills courses.