Deploying Meteor applications Deploying Meteor applications Apr. 2nd, 2015 Patrick Coffey

Deploying Meteor applications

April 2nd, 2015

This post is the fourth in a series of posts about the new JavaScript framework Meteor. If you are unfamiliar with Meteor check out the introduction post in this series or go through the demos available on Meteor’s project website.

So… you’ve built a gorgeous Meteor application! You’ve artistically structured a gorgeous codebase that comes together to present a performant, delicious application that your consumers will love. What’s the last piece of the puzzle? Deployment.

Where to deploy… ?

Heroku? Rackspace? Linode? DigitalOcean? There are plenty of options when it comes to hosting your application. I’m a pretty big Heroku fan, and there’s a reall nice heroku build pack for Meteor, courtisy of jordansissel. I’m not going to talk about that in this blog post, as it’s very straightforward. Instead, I’m going to talk about how to deploy your Meteor application to a Linux distro.

Running Meteor on a Linux distro

The first thing you should know about deploying Meteor is, it’s not the same as running meteor within your app root to develop your application. Once you’re ready to deploy your application, you can use Meteor’s build system to generate a bundle that can be sent to a server, unpacked, and run.

Installing the tools

You need to install the following things to run a Meteor app bundle on a Linux distro:

  • A box running Linux 🙂
  • MongoDB
  • NodeJS
  • g++ make
  • A web server (like Apache or Nginx)

MongoDB

For debian-based Linux systems, you can install MonboDB by running:

For other linux distros that are not debian-based, see the MongoDB installation documentation..

Now, you don’t want this MongoDB instance to be available to external hosts. You can use netstat to make sure MongoDB is only serving the local host, look for ports 27017 and 28017.

NodeJS

Run the following commands to install NodeJS on debian-based Linux systems:

It’s generally safe to assume that Meteor is going to require a more recent version of NodeJS than what is available in aptitude’s repositories. This is why I suggest using the chris-lea repository.

g++ make

Meteor depends upon some npm modules that require g++ make tools to run correctly, so you need to install it on your server:

Web server

In the past I have used Nginx to serve my Meteor applications. Apache will also work well. All you really need to do is set up a proxy pass to the port that Meteor is running on. There is a really good document with an example Nginx available on Meteorpedia.com. I’d encourage you to read through that and use the example code if you’re not familiar with Nginx.

Bundling and running Meteor

Step 1: Create the bundle

Start off by navigating to the root of your application in a terminal window, and run this command:

This will generate a tar.gz file (bundle) in the directory that you specified.

Step 2: Unpack the bundle

Next, copy the bundle up to your newly-configured Linux server.

Once this has been uploaded to your server, ssh into your server and unpack the bundle:

Step 3: Install Meteor’s dependencies

You’ll need to tell npm to install all the modules Meteor needs to run properly:

Step 4: Run Meteor

While you are still inside of the server directory in the bundle you unpacked, you can crank up your Meteor applications:

Of course, some packages you use may require that you pass in more environment variables (like MAIL_URL), so make sure you enclude all the environment variables your application needs.

Once you have started Meteor, you should be able to reach it by pointing a browser at your server. Party time!

Next Steps

Once you have your Meteor application running, you may want to take some extra steps to make sure that your application keeps running.

Here’s some things you may want to set up:

  • Upstart – You can set this up so that your Meteor application is automatically run on system boot. You can even configure it to restart Meteor if something goes wrong.
  • forever.js – A (simpler) alternative to upstart.
  • MongoDB Client Acces Control – This will require all users connecting to MongoDB to identify themselves.

Tools

I’ve been working on some toolsets that will make the process of building and deploying a Meteor application easier. This will most likely be in the form of a Vagrant playbook. So, stay tuned 🙂


This post was originally published on my personal blog here.

Comments