Skip to main content
If you want to figure out your hosting solution completely from scratch, the Meteor tool has a command meteor build that creates a deployment bundle containing a plain Node.js application. This approach gives you complete control over your deployment infrastructure but requires more manual setup and maintenance compared to managed solutions.

Building Your Application

The meteor build command creates a deployment bundle that can run on any server with Node.js and MongoDB.

Prerequisites

Before building, ensure all npm dependencies are installed:
Any npm dependencies must be installed before issuing the meteor build command to be included in the bundle.

Build Command

Create a production bundle for deployment:
It’s important that you build your bundle for the correct architecture. For example, if deploying to a Ubuntu Linux server, use os.linux.x86_64.

Build Options

  • --architecture - Specify the target architecture (e.g., os.linux.x86_64)
  • --directory - Build to a directory instead of a tarball
  • --server-only - Don’t build mobile apps
  • --server - Set the ROOT_URL (for mobile builds)
Examples:

Understanding the Bundle

The meteor build command produces a .tar.gz file containing:
  • bundle/ - The application bundle directory
    • main.js - Application entry point
    • programs/ - Server and client code
      • server/ - Server-side code and npm dependencies
      • web.browser/ - Client-side code
    • .node_version.txt - Required Node.js version
    • star.json - Bundle metadata

Deployment Steps

1

Build the Application

Create the deployment bundle:
2

Transfer to Server

Copy the .tar.gz file to your server:
3

Extract the Bundle

On the server, extract the bundle:
4

Install Server Dependencies

Install Node.js dependencies for the server bundle:
5

Run the Application

Start the application with required environment variables:

Required Environment Variables

Your Meteor application requires these environment variables to run:

ROOT_URL

The base URL for your Meteor project:
This is used to generate URLs to your application by various packages, including the accounts package.

MONGO_URL

A MongoDB connection string URI:
In production, you must specify a MONGO_URL. In development, Meteor automatically connects to a local MongoDB instance.

PORT

The port at which the application is running:

METEOR_SETTINGS (Optional)

Settings as a stringified JSON object:

Node.js Version

The environment you choose will need the correct version of Node.js and connectivity to a MongoDB server. To find out which version of Node you should use:
  1. Run meteor node -v in the development environment
  2. Check the .node_version.txt file within the bundle
  3. For Meteor 3.x, you’ll need Node.js 20.x
If you use a mismatched version of Node when deploying your application, you will encounter errors!

Example Deployment Script

Here’s a complete deployment script you can adapt:
deploy.sh

Process Management

For production deployments, use a process manager to keep your application running:

PM2

PM2 is a popular Node.js process manager:

Systemd Service

Alternatively, create a systemd service:
/etc/systemd/system/meteor-app.service
Enable and start the service:

Reverse Proxy Setup

For production deployments, use a reverse proxy like Nginx to:
  • Handle SSL/TLS termination
  • Serve static files efficiently
  • Load balance across multiple instances
  • Add security headers

Nginx Configuration

/etc/nginx/sites-available/meteor-app

Meteor Up Alternative

Meteor Up (mup) is a third-party, open-source tool that automates the manual steps of using meteor build and deploying to your server. Meteor Up can SSH into any server running Ubuntu or Debian and handle the deployment process for you. Get started with the Meteor Up tutorial.

Key Features

  • Automated deployment via SSH
  • Docker-based deployments
  • Zero-downtime deployments
  • SSL certificate management
  • MongoDB setup and management
  • Environment variable management
  • Deployment rollback support

AWS Elastic Beanstalk Plugin

The mup-aws-beanstalk plugin deploys Meteor apps to AWS Elastic Beanstalk instead of a server. It supports:
  • Autoscaling
  • Load balancing
  • Zero downtime deploys
  • Managed infrastructure

Best Practices

Always use a process manager like PM2 or systemd to ensure your application restarts automatically on crashes or server reboots.
Use Nginx or similar reverse proxy for SSL termination, static file serving, and additional security.
Always specify the correct architecture when building to avoid runtime errors.
Keep track of deployed versions and maintain deployment scripts in version control.
Implement health checks and monitoring to detect issues early.
Set up automated MongoDB backups to prevent data loss.

Troubleshooting

Build Errors

  • Ensure all npm dependencies are installed before building
  • Check that you have enough disk space for the build
  • Verify you’re using a supported Node.js version

Runtime Errors

  • Check that all environment variables are set correctly
  • Verify MongoDB is accessible and credentials are correct
  • Ensure the Node.js version matches the one used to build
  • Check application logs for specific error messages

Connection Issues

  • Verify firewall rules allow traffic on the specified port
  • Check that reverse proxy is properly configured
  • Ensure WebSocket connections are supported
  • Verify ROOT_URL matches the actual domain

Performance Issues

  • Use a production MongoDB with proper indexing
  • Implement caching strategies
  • Configure CDN for static assets
  • Use WebAppInternals.setBundledJsCssPrefix() for CDN
  • Monitor resource usage (CPU, memory, disk)

Additional Resources