Deploy to production with Meteor Up
Today we’ll take a closer look into the process of deploying a Meteor application into production with a very nice NPM-Package called Meteor Up (mup) which was developed by Arunoda Susiripala.
So you have a Meteor application you want to deploy in a production ready environment, but you have no idea how to setup the server / database on which the application will run?
The solution is the Meteor up NPM-Package. With just a few commands you can setup your server and deploy to it so that your application is deployed in a production ready manner!
1. Install the npm-Package
The first thing you need is the Meteor Up NPM-Package which is available through the npm package manager. Just run
npm install -g mup<br />
and you are up and running.
2. Create a Meteor up project
This might sound a little bit intimidating, but you need to create a new Meteor up project. This is done with simply one command. Run the following commands to create a new Meteor up project:
mkdir ~/my-meteor-deployment<br />
cd ~/my-meteor-deployment<br />
mup init<br />
A Meteor up project can live anywhere on your computer (it doesn’t have to be in your Meteor applications folder). It contains the information for your server and your deployment configurations. This way you can e.g. share the deployment-Information with your teammates via Dropbox (just create a shared folder with your Meteor up project.
3. Setup your Meteor up project
You’ll get two generated files once you’ve created your Meteor up project. A settings.json-File (if not already present) and a mup.json-File.
The settings.json-File is the standard Meteor settings.json-File. This file will be used by Meteor up to apply settings for your production environment. You put in stuff like your kadira API keys or Google API keys.
The mup.json-File contains all your important configuration for your production environment and may look like this:
{<br />
"servers": [<br />
{<br />
"host": "hostname",<br />
"username": "root",<br />
"password": "password"<br />
}<br />
],</p>
<p> "setupMongo": true,</p>
<p> "setupNode": true,</p>
<p> "nodeVersion": "0.10.36",</p>
<p> "setupPhantom": true,</p>
<p> "enableUploadProgressBar": true,</p>
<p> "appName": "meteor",</p>
<p> "app": "/path/to/the/app",</p>
<p> "env": {<br />
"ROOT_URL": "http://myapp.com"<br />
},</p>
<p> "deployCheckWaitTime": 15<br />
}<br />
It is well commented (I’ve removed the comments in the code snippet above for a better readability) and documented but let’s take a closer look into the important parts:
Line 2: Servers
This Array includes all the servers you have (yes you can deploy to multiple server at the same time). Let’s assume you have one server with the IP 145.345.23.1. The Username is “meteor” and the password is “test”. Just fill out the object with the correct information (the hostname could be the hostname of your server or the IP address).
Line 10: Setting up Mongo
It is possible to use external MongoDB providers such as Compose or MongoLab (which is highly recommended). We’ll run MongoDB on our own server for this simple production deployment (I’ll write another Blog post how you can use external Database providers with Meteor Up). Just leave this configuration as it is. Meteor up will take care and setup MongoDB on your server for you.
Line 20: App name
This name is the name of your application. It’s used internally on your server. You could you basically any name you want (but stick to e.g. JavaScript naming conventions). Let’s assume our app name is “Awesome Meteor Project”. So our app name for the mup.json-File would be “awesome-meteor-project”.
Line 22: App location
This is the location to your app on your machine. It’s recommended to use full paths.
Line 24: Environment configuration
This object contains environment configuration such as the ROOT_URL or the MAIL_URL for your Meteor project. The root url should be set. Otherwise your application might not function as expected. Just paste in your domain or IP address which points to your server and you are good to go. That’s it for now. The next step is to setup the server (install Node, MongoDB, …)
4. Setup your server
cd into the Folder where your Meteor up project lives and run:
mup setup<br />
That’s it. Meteor up will now look into your configuration and configure your server accordingly. This might take some time. After this step your server is ready to receive the Meteor application to run it.
5. Deploy your Meteor application
cd into the Folder where your Meteor up project lives and run:
mup deploy<br />
Your application is now bundled and uploaded to the preconfigured server. You should be able to access your application through the IP address or Domain which points to your server after this step is finished. That’s it.
6. Update your application / server configuration
If you change something in your code and want to redeploy, you just need to run
mup deploy<br />
again and you application is updated.
The same applies if server-Related configurations need to be updated. But in this case you need to run
mup setup<br />
again.
Troubleshooting
A good place to look for troubleshooting is the issues-Page for Meteor up and search through all the issues. Researching this nearly answered all of my Meteor up related problems.
I hope that this posts was helpful for you to get started with the deployment of your Meteor application on your own server.