Deploy your Meteor app with PM2

PM2 is a well-known node process manager. Not so well-known is its deployment feature. With pm2 you can reasonable easy deploy any node application. As Meteor is always a node app at its heart I’ve decided to deploy my current Meteor project with PM2.

I assume you already have PM2 installed on your client and server, otherwise checkout

To create a deployment configuration file run pm2 ecosystem in your project folder. This will create the ecosystem.config.js file. You can now configure this file according to your projects environment.

Here’s mine:


module.exports = {
   * Application configuration section
  apps: [
      name: 'Project',
      script: './bundle/main.js',
      env: {
        NODE_ENV: 'dev',
        MONGO_URL: 'mongodb://',
        ROOT_URL: '',
        PORT: 3000,
          'private': { ... },
          'public': { ... }
      env_prod: {

   * Deployment section
  deploy: {
    dev: {
      user: 'login',
      host: '',
      key: '/path/to/your/ssh/id_rsa',
      ref: 'origin/develop',
      repo: '',
      path: '/path/to/your/project/folder',
      'post-deploy': 'rm -rf ./bundle && npm install --production && meteor build . --directory && cd ./bundle/programs/server && npm install --production && cd ../../.. && pm2 startOrRestart ecosystem.config.js',

Hint: If your git repo is private, make sure your store a ssh key with access rights to the repo on your server.

The post-deploy command will build the node app from your Meteor project. This command once executed takes some time to finish.

When you’re finished updating the config file, you have to set up the project folder on your server.
Run pm2 deploy ecosystem.config.js dev setup to so. Your repo will be cloned and launched on your server.

From now on, whenever you’ve pushed new changes to your repo, you can deploy your app with pm2 deploy ecosystem.config.js.

Meteor app deployed successfully.

Make sure to have a look on the PM2 deployment documentation.

Leave a Reply