Different Ways to Deploy a Meteor Application

Learn how to upload a Meteor application to a server.

Deploying a Meteor application

After developing an application, we may want to host it on a server. MeteorJS is an open-source, Node.js framework, which means that we can run MeteorJS applications in production the same way we’d run a Node.js application. There are various methods that deploy the application to the server. We could classify these methods as follows:

Manual method

The project is deployed manually. We have to do everything ourselves, such as transferring the server code to the server and setting up the environment variables. The application is built by running the build command of the Meteor CLI tool on the terminal.

meteor build --directory ../output

The command above outputs the Meteor application bundle in a folder called output, located outside the application project folder as specified by the command. The output folder contains a folder named bundle that has our application code.

Meteor requires that Node.js is installed on the server before it will run. We want to use a change directory command (cd) to get into the programs/server directory and install dependencies by running npm install from the terminal. We’ll need to export some environment variables required for the application to run.

export MONGO_URL "mongodb://user:password@host:port/databasename"
export ROOT_URL  "http://yoursite.com"
export MAIL_URL "smtp://user:password@mailhost:port/"

After exporting the environment variables, we start the application server by running the code below on the terminal of the program/server directory:

Note: The environment variables above are placeholders that should be replaced with real values when the application is deployed.

node main.js

The node main.js code starts up the application. We could access the application using the exported ROOT_URL. Manual deployment like this isn’t encouraged and is difficult to scale.

The server process could be terminated by an error, causing the application to go offline. To mitigate this, we could install a process manager watcher like **PM2*8, which automatically starts up the Node process if it dies.

Deploying to Galaxy

Meteor recommends that we use Galaxy (Galaxy is a premium Cloud Solution Engineered for Meteor Apps), a premium cloud solution engineered for Meteor apps, to host and run our Meteor-based application. Running on Galaxy removes the pain of having to manage our application infrastructure ourselves. Galaxy makes the hosting and monitoring of the application easy.

To deploy to Galaxy, we have to sign up for an account. It’s recommended to use the MongoDB database as a service. Before deploying the application, we’ll need to set some environment variables required to run the application. Remember that we can set our environment variables using our settings.json file.

There are several required environment variables we need to set when running on the Galaxy plaftorm.

  • The MONGO_URL is the location of the MongoDB database of our application.
  • The ROOT_URL is the root URL of the application. That’s the location from which the application is served.
  • The MAIL_URL is required in order to send an email from our application.
  • The GALAXY_NODE_OPTIONS is for any Node settings that can be controlled at the command line.
  • The USER_LOG_DESTINATION is the location that can be configured to store custom logs.

To deploy our application to Galaxy, we should go to the command line in the application directory and type the following code

DEPLOY_HOSTNAME=galaxy.meteor.com meteor deploy your-app.com --settings production-settings.json

This uploads the application to the Galaxy server, and we can then start monitoring our application from the dashboard.

Automating the deployment process

Meteor application deployment can be automated by the use of a deployment tool called Meteor Up. Meteor Up comes bundled with a lot of functionality, making the deployment process very easy.

Meteor Up is installed globally on our development machine through npm. It helps to bundle our application and push it to a production server. It uses a config file in which we specify deployment options. Here are some of the functionalities provided by Meteor Up:

  • It auto restarts the app if it crashes.
  • It auto restarts after the server reboot.
  • It runs the application inside a Docker container for better security and isolation.
  • It reverts to the previous app version if the current deployment fails.

The deployment process we decide to use depends on the resources we’re willing to spend. If we want absolute peace of mind knowing that our app or server infrastructure is being managed properly, then Galaxy will be our best route. If you’re a hands-on kind of person, using Meteor Up will appeal more to you.

Get hands-on with 1200+ tech skills courses.