Up and Running with Meteor and Heroku

I stumbled across meteor in the weeks during my leave after the birth of my daughter. I’ve used php and python to build apps for work and play in the past, but reading hackernews re-piqued my interest in the node.js codesphere. Here are the details of getting up and running with meteor and heroku.

meteor

Meteor is a js framework featuring tight integration between client and server. I installed meteor according to the docs and tried out the examples. After that was done, I moved on to building my own app locally.

When it came time to deploy, there were a few options:

  1. use meteor deploy to push to a subdomain of meteor.com
  2. use meteor bundle to deploy on my own node.js setup somewheres

I chose the second, electing to use a free heroku account to host the app. I ended up not bundling the app locally, opting instead for a buildpack. More on that in a second.

To harden the app before public deployment, I disabled client db updates:

if (Meteor.is_server) {
  Meteor.startup(function () {
    //option 1: without underscore, works with default meteor install
    Meteor.default_server.method_handlers['/foo/insert'] = function () {};
    Meteor.default_server.method_handlers['/foo/update'] = function () {};
    Meteor.default_server.method_handlers['/foo/remove'] = function () {};

    //option 2: with underscore (meteor add underscore)
    _.each(['foo', 'bar'], function (collection) {
      _.each(['insert', 'update', 'remove'], function (method) {
        Meteor.default_server.method_handlers['/' + collection + '/' + method] = function () {};
      });
    });
  });
}

heroku

I signed-up for a free heroku account to get started.

After trying and failing to perform the steps manually, I stumbled across this buildpack that automates most of the process.

With the buildpack, you can deploy straight from your meteor code (you don’t have to bundle first):

meteor create sampleproject
cd sampleproject

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

Create the heroku app with the buildpack:

heroku create appname --stack cedar --buildpack https://github.com/jordansissel/heroku-buildpack-meteor.git

And now you can just commit/push whenever you want to deploy:

git commit -m "commit details"
git push heroku master

Sidenotes

heroku ssh keys

After my initial login to heroku, I changed my ssh keys to setup my github account. You can update your ssh keys with heroku with the following:

heroku keys:add ~/.ssh/id_rsa.pub

heroku app name

If you don’t specify the app-name at creation, heroku assigns a randomized name for you. You can change the name via cmd line:

heroku rename

If you change the app name via the heroku dashboard, you’ll need to update the git remote config:

git remote -v
git remote rm heroku
git remote add heroku git@heroku.com:appname.git

References:

Back