Loading a specific file into Dotenv

Loading a specific file into Dotenv. A quick guide for when you want to run Ruby files from outside of a document root

Dotenv is a great tool and by default works right out of the box when you have a .env file.

Sometimes your .env file is in a different location than the root of your project.

Or sometimes if you are writing single Ruby scripts that use Dotenv you might want to execute them from outside of the root of the script.

In these cases you can load in the file by explicitly telling Dotenv.load what file you want to load.

  Dotenv.load './my/location/for.env'

Recent posts View all

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.