Load environment variables with dotenv
I released dotenv, a handy Ruby gem that makes loading environment variables 100% less painful in development, guaranteed or your money back.
Backstory
I love the emerging practice of storing application configuration in environment variables. It makes it ridiculously easy to keep secure data out of your code repository while still making it available at runtime. But it slightly complicates development. It’s not always practical to set all of those environment variables on your development machine or continuous integration server where you might run multiple projects.
Foreman provides this handy feature of loading variables from .env, which works great for anything that you want to put in your Procfile. But it doesn’t help you when you run your app manually, run a rake task, or open up the console. My co-workers got tired of me saying Works For Me™, so dotenv solves that problem.
Frontstory
For Rails 3 apps, dotenv will automagically load variables from .env into ENV whenever the environment is bootstrapped. For non-Rails apps, it’s a simple one-liner to load .env. Check out dotenv on GitHub for all the gory details.
8 Comments
Have you tried `foreman run`?
Raul: Yep. However, asking everyone on the development team to type
bundle exec foreman run rails consoleis not exactly practical. This makes it just work without any other considerations.Well, that’s why shell aliases are so useful, or do you really type `bundle exec` all the time? :)
I mention `foreman run` because it actually helps “you when you run your app manually, run a rake task, or open up the console”.
That said, it’s great to have different options out there, thanks!
Raul: Yep, I use aliases. But still,
rails consoleshould just work. It’s what everyone is used to and has caused our team enough pain that I put together this tiny gem.P.s. Sorry about the typo on your name on the first reply. Stinking OS X autocorrect. Fixed now.
Brandon: Superb gem. We use heroku and have been trying to get our dev environments to match production as much as possible. I fully agree with your “asking everyone on the development team to type
bundle exec foreman run rails consoleis not exactly practical” premise.Internet high-five!
I tend to use `rbenv-vars` to load environment vars or foreman.
This gem is a good attemp to make env files work with Rails application but you need to load those variables before any process starts, otherwise some variables are missing. See the issue I created at GitHub. https://github.com/bkeepers/dotenv/issues/10
Why don’t use simply `.pam_environement` file. This file is manage by your shell to set all variable you want. because we can’t use dot-env in our shell command :(
Downvote for using the word “automagically”.
Post a Comment