Motivation

Meteor apps are fast to develop and easy to deploy locally. As nice as it is to view your app this way, it’s also great to see how it performs in the wild. We’re using Heroku as it offers a free dyno to host our app on.

Meteor recently updated from v1.3 to v1.4. This includes an update to Node from v0.10.41+ to v4.4.7 and to the latest MongoDB 3.2.6. These potentially break newly updated Meteor apps on hosted on Heroku due to versioning issues. This tutorial will cover both setting up a Meteor 1.4 applet as well as reliably deploying it to Heroku.

Required Software

There are a few applications that must be installed before we continue:

  1. Meteor
  2. Heroku
  3. Git

Create and Configure a Meteor App

For this tutorial, we will name our app “example”:

meteor create example
cd example

Now that our app is created, we need to manage it with git:

git init
git add .
git commit -m "first commit!"

Create Heroku Instance

Create an account on Heroku if you haven’t already, then do the following:

heroku login
heroku apps:create example

If you don’t care about a specific name for your app, you can run heroku create instead.

Set Buildpack for Heroku Instance

Meteor needs a buildpack in order to be executed by the Heroku dyno manager. As Heroku’s cedar stack has no default language/framework support, the buildpack determines the framework for us. Unfortunately, Heroku does not have official Meteor support. To get around this, we will use a third-party custom buildpack.

For our app, we will use the reliable Meteor Buildpack Horse:

heroku buildpacks:set https://github.com/AdmitHub/meteor-buildpack-horse.git

Create and Configure a New mLab Instance

We need an external MongoDB database to have database support in our Heroku instance. We use mLab as it’s free and provides ~500MB of storage.

heroku addons:create mongolab:sandbox

Now we need to configure our Meteor app to use this database. First we get the MongoLab URI:

heroku config | grep MONGODB_URI
# Running "heroku config" will list all configuration flags set on your app

Next, we configure our Meteor app to use this address:

heroku config:add MONGO_URL=<MONGODB_URI value>
heroku config:add ROOT_URL=https://example.herokuapp.com

You can also configure mLab via Heroku’s website. To do this, navigate to mLab’s addon page and install it on your app. At that point, it should be possible to get the MONGODB_URL and configure the MONGO_URL appropriately.

Deploying to Heroku

We must check that we can push to Heroku:

git remote -v
# Output should be:
# heroku  https://git.heroku.com/example.git (fetch)
# heroku  https://git.heroku.com/example.git (push)

If the output doesn’t match your git repos, you can run:

git remote add heroku https://git.heroku.com/example.git

Running git remote -v should have the desired output.

Now we can deploy the app:

git push heroku master

Closing Remarks

Now with your app up on Heroku, you can share your project with anyone and everyone. If you decide to scale up your app, consult the Heroku Docs on how to do so. In addition, you will need to enable Session Affinity. Otherwise, happy coding!

Leave any any questions, comments, or suggestions below. You can also e-mail me at [email protected].

Footnotes

Meteor

Meteor is an open-source, full-stack JavaScript development platform for rapid app development. You can view the full Meteor API here. Top ↑

Heroku

Heroku is an excellent PaaS provider for hosting your app in the cloud. Scaling your app is easy and there are plenty of add-ons to ready your app for whatever audience you’re targeting. Top ↑