Running meteor with pm2

Hi folks, do you have any experience in running meteor with pm2. I owuld just simply want to run my meteor app on DO droplet like i run simple node servers. I found pm2-meteor - npm. But seems it is out of maintenance and provides many things i would never use. Is there any way as simple as pm2 start index.js i used to run in simple node scenarios? Thx in advance.

Hello, we are using pm2 like this :

NVM_DIR=__deployPath__/.nvm NODE_ENV=production pm2 start bundle/main.js --name __deployName__

where deployPath is the path to your app and deployName is your app name
You can also use a file to describe all env variables and meteor settings



Check out this link for using PM2 with meteor


Take a look at my in depth guide for running Meteor on PM2:


I’m still using pm2-meteor on multiple apps, and very happy with it. Once you have the config-file which takes care of the env-vars, it’s a single command to deploy.

1 Like

Hi @james. Nice work. Anyways maybe you know what is the reason of error i got. Build works fine then it properly uploads, but during execution remote script i got :

0|staging  | Error: Cannot find module 'reify/lib/runtime'
0|staging  | Require stack:
0|staging  | - /home/ubuntu/staging/bundle/programs/server/runtime.js
0|staging  | - /home/ubuntu/staging/bundle/main.js
0|staging  |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
0|staging  |     at Module.Hook._require.Module.require (/usr/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
0|staging  |     at require (internal/modules/cjs/helpers.js:74:18)
0|staging  |     at Object.<anonymous> (/home/ubuntu/staging/bundle/programs/server/runtime.js:10:3)
0|staging  |     at Object.<anonymous> (/home/ubuntu/staging/bundle/programs/server/runtime.js:53:3)
0|staging  |     at Module._compile (internal/modules/cjs/loader.js:999:30)
0|staging  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0|staging  |     at Module.load (internal/modules/cjs/loader.js:863:32)
0|staging  |     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|staging  |     at Module.require (internal/modules/cjs/loader.js:887:19) {
0|staging  |   code: 'MODULE_NOT_FOUND',
0|staging  |   requireStack: [
0|staging  |     '/home/ubuntu/staging/bundle/programs/server/runtime.js',
0|staging  |     '/home/ubuntu/staging/bundle/main.js'
0|staging  |   ]
0|staging  | }

When it comes to binaries, I think there are still some problems even with my script. For my deployment I had to add some more stuff inside

echo "Installing npm packages"
cd bundle/programs/server
rm -rf node_modules/sharp/vendor
rm -rf npm/node_modules/sharp/vendor
rm -rf node_modules/mozjpeg/vendor
rm -rf npm/node_modules/mozjpeg/vendor
meteor npm install --production &> /dev/null

I looked at reify on npm and don’t see any reference to a bundled binary but you could maybe try this on your remote script.

echo "Installing npm packages"
cd bundle/programs/server
rm -rf node_modules/reify/vendor
rm -rf npm/node_modules/reify/vendor
meteor npm install --production &> /dev/null

i solved it temporary by going there and manually run ‘npm install’ anyways i now see another problem that it seems to have problem with I see now “MONGO_URL must be set in environment” While it is set in
It must be something wrong with meteor it self because even if i go there and manuall run.

MONGO_URL=my_mongo_url ROOT_URL=..my_root_rl node main.js

It shows the same error. While obviously MONGO_URL is provided.
More intresting is fact that it you placesome shit in MONGO_URL like MONGO_URL=blahblah it properly tells that connection string is invalid.

You have any special chars? Try wrapping it in quotes like…

export MONGO_URL="mongodb://"

Yep this was solution. However this is definietly bug in meteor, problem should be reported properly. Anyways now it says " MongoError: setName from ismaster does not match provided connection setName [atlas-nyb1n1-shard-0] != [example-staging-shard-0]" but when i deploy using your script, kill the app and then ssh to the server and manually run it there from command line it works. Interesting. I will let know if i will find something.