How to use PM2 in an meteor project?

Hi there,
PM2 seems to be not suitable with meteorJS.

import { Meteor } from 'meteor/meteor';
import { pm2 } from 'pm2';

//also tried non-daemon mode with pm2.connect(false....
pm2.connect(function(err) { //start up pm2 god
  if (err) {

    script    : 'path/to/binary',         
    exec_mode : 'fork',
    //args: params,  //separate them params with commas
  }, function(err, apps) {
    pm2.disconnect();   // Disconnect from PM2
    if (err) throw err

the same logic/codes works fine in a nodeJS application. Am i missing anything or is it a meteor related issue?

thanks for your time

1 Like

pm2 uses require syntax, so you should use either:

import pm2 from 'pm2';


const pm2 = require('pm2');

thanks for the quick reply. I tried this as well. PM2 launches up without any issue (checked the running process). The only problem i am having is that the defined binary is not being launched. For some reason the pm2.start does not get executed. Any idea?

EDIT: the function is erroring and the error is null

Not sure - I’ve just done essentially the same test you did and it worked fine. Have you checked ~.pm2/logs/ for stderr and stdout data?

weird. I am on OSX 10.12.X and my pm2 version seems to be

In memory PM2 version: 2.8.0
Local PM2 version: 2.3.0

What OS are you on?

tried pm2 update - keep showing 2.3.0 as local version.
the error and stdout data is empty. If i do pm2 list after running the above meteor app (even with your suggested edits) it is empty. Seems it won’t run the binary but only launch up pm2.

Ubuntu 16.04.

Not sure about your version differences. I just installed pm2 from scratch (meteor npm i -g pm2), created a new meteor project, and installed the API in that (meteor i --save pm2). Incidentally, that’s v2.8.0.

Is your script path correct? You could try with something like /bin/ls

@robfallows - trying it with something like ls or date indeed works well. Using it with my custom binary located in myproject/private/bins/binary or myproject/server/binary fails. Any idea on how i could fix this? I suspect its a path related issue.

EDIT: placing the custom binary in a place like /Applications/ on osx or /usr/bin on linux is a hackaround. I still prefer executing the binary out of my meteor application folder.

Are you using relative paths (including implied relative) - paths like app.js, bin/

If you are, you need to be aware that in development mode, your app is not running in your project root - it’s actually in /path/to/your/app/.meteor/local/build/. In production, it’s relative to the ROOT_URL environment variable.

So, either use absolute paths, or the ostrio:meteor-path package is a handy way to find the current root of your app.