A while back, I made a post about deploying yesod apps to heroku. The method used back then is no longer required (thank God!) and deploying to heroku is super simple these days. So simple, in fact, that I won’t reiterate those instructions here, this post is about something a bit more specific.

Chances are, your app is using a database. And you probably don’t want to hard-code those database credentials in your (probably shared) source code. What you’d rather do is parse them out of the DATABASE_URL environment variable provided by heroku.

Well, here is how you do that:


Eventually, I might wrap this up in a cabal package you can install, but for now just create a helper like this:


This relies on the heroku package, so be sure you add that to the build-depends in your cabal file.


Now, modify your application loading like so:


That’s it. Commit, push, enjoy!

07 Jun 2013, tagged with haskell