Questions tagged [pm2]

PM2 is a CLI process manager for Node.js applications with a built-in load balancer

pm2 is a process manager for Node apps with a built-in load-balancer.

pm2 is perfect when you need to spread your stateless NodeJS code across all CPUs available on a server, to keep all processes alive forever and to 0s reload them. pm2 reloads scripts when they crash, can manage multiple processes at once, and all without downtime.

It is an NPM CLI application that runs in io.js and node.js on Windows, Mac OSX, and Linux.

Main features

  • Builtin load-balancer (using the native cluster module)
  • Script daemonization
  • 0s downtime reload for Node
  • Startup scripts for Ubuntu and CentOS
  • Stop unstable process (avoid infinite loop)
  • Monitoring in console
  • HTTP API
  • Remote control and real time interface API

Questions can be tagged with "pm2" for problems with running applications using pm2.

For more information:

2258 questions
43
votes
7 answers

How to run pm2 so other server users are able to access the process?

When I start my Nodejs app with pm2, other server users are not able to access the process. Even if I start pm2 from a custom directory (not current user's ~/, what pm2 is using by default): HOME=/var/www pm2 start app.js Directory is accessible by…
Nik Sumeiko
  • 8,263
  • 8
  • 50
  • 53
43
votes
3 answers

How to specify a port number for pm2

I'm trying to use pm2 to manage a node.js cluster pm2 start . -i 3 I'm currently running the app on heroku and using a Procfile with the above command, but I cannot figure out how to configure pm2 to use the existing PORT env var. Something like…
Luke W
  • 8,276
  • 5
  • 44
  • 36
43
votes
4 answers

Can the pm2 node module restarts the app after crash automatically

I have a Node.js app ready which is workable, but has known and unknown bugs which crash the app. In such cases it would be nice if pm2 can restart the node app. Is this feature already available in pm2?
Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135
38
votes
3 answers

Debug application which is run using pm2

Application is run by pm2 start app.js or pm2 start config.json I want to debug my application locally using node_inspector. I added debug argument pm2 start --node-args="--debug=7000" app.js It works fine but if I provide config.json instead of…
Nawa
  • 2,058
  • 8
  • 26
  • 48
36
votes
1 answer

What's the difference between pm2 and pm2-runtime?

I've been transferring some projects that have been executing on the same machine to individual dockers each. I've tried to use pm2 on one of these docker projects to make sure the service would restart if something go wrong (it's a volatile…
Ruan Kotovich
  • 579
  • 1
  • 4
  • 11
36
votes
6 answers

Windows: Auto start PM2 and node apps

At a Windows AWS server i have a NODE app and i'm using PM2 to launch the app I have tried the NPMs: "pm2-windows-startup" and "pm2-windows-service" But after i restart my AWS instance and run PM2 ls No node app shows up in the list... I followed…
PabloDK
  • 2,181
  • 2
  • 19
  • 42
35
votes
4 answers

What is the `PM2` for command `yarn run start`?

I run the nodejs app with yarn run start , what is the command for pm2 I should use? pm2 yarn run start give me an error. My package.json content "scripts": { "start": "budo main.js:dist/bundle.js --live --host 0.0.0.0", "watch": "watchify…
tree em
  • 20,379
  • 30
  • 92
  • 130
35
votes
2 answers

Use sudo inside Dockerfile (Alpine)

I have this Dockerfile ... FROM keymetrics/pm2:latest-alpine RUN apk update && \ apk upgrade && \ apk add \ bash COPY . ./ EXPOSE 1886 80 443 CMD pm2-docker start --auto-exit --env ${NODE_ENV} ecosystem.config.js How can I…
ridermansb
  • 10,779
  • 24
  • 115
  • 226
35
votes
2 answers

Node.JS built in cluster or PM2 clustering?

Which one is better? I have activated Nodejs clustering mode with workers but now I discovered PM2 that does the same thing. I'm using keymetrics to see the stats from my webserver and I have noticed that when I launch my NodeJS node (with a built…
llf
  • 483
  • 1
  • 4
  • 9
34
votes
7 answers

Start app as root with pm2

I have a daemon that must be run as root on startup. I use pm2 to start other apps but can not figure out if it can start an app as root. Can it be done? If not, what are my options?
Martin Nilsson
  • 659
  • 1
  • 8
  • 17
33
votes
4 answers

Kill a Docker Container

I've set up a Docker container for my node app and ran it using docker run -p 4500:4500 my_node_app It launched pm2 in no-daemon mode. CTRL+C and exit don't work. I've tried docker stop my_node_app in another terminal window but to no avail.…
Coder_Nick
  • 781
  • 1
  • 8
  • 25
33
votes
2 answers

PM2 log output limits

I'm happy with how PM2 formats and outputs the log with pm2 logs app But currently it truncates the log to 20 last entries: [PM2] Tailing last 20 lines for [app] process ... Is there a way to change the limits and output it in a similar manner,…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
32
votes
5 answers

How can I run pm2 on a certain node version?

There are several different versions of node running on our linux server, And my service is based on node v0.11.14. However, other people's code have to run on lower version of node(lower than v0.11) otherwise their services will be out of service.…
hwoarangzk
  • 337
  • 1
  • 3
  • 8
31
votes
5 answers

Where can I find the ports of all running pm2 apps?

I have a server with PM2 installed and 10 running node apps. Every App should run with a different port number. When I install a new App on the server I need the information about the used ports. With 'pm2 list' I get much info about the apps but…
Schmidko
  • 690
  • 1
  • 7
  • 17
29
votes
6 answers

How to pass NODE_ENV=production to pm2?

I have this node app deployed and runs fine with NODE_ENV=production yarn start. I can demonize the app using pm2 start npm -- start but then it defaults to NODE_ENV=development config. And when I use pm2 start npm -- start NODE_ENV=production…
narad
  • 499
  • 3
  • 6
  • 11