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
407
votes
22 answers

Can pm2 run an 'npm start' script

Is there a way for pm2 to run an npm start script or do you just have to run pm2 start app.js So in development npm start Then in production with pm2 you would run something like pm2 start 'npm start' There is an equivalent way to do this in…
svnm
  • 22,878
  • 21
  • 90
  • 105
175
votes
18 answers

mongoError: Topology was destroyed

I have a REST service built in node.js with Restify and Mongoose and a mongoDB with a collection with about 30.000 regular sized documents. I have my node service running through pmx and pm2. Yesterday, suddenly, node started crapping out errors…
dreagan
  • 2,426
  • 6
  • 24
  • 34
143
votes
3 answers

what is the point of using pm2 and docker together?

We have been using pm2 quite successfully for running apps on our servers. We are currently moving to docker and we saw http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/ But what is the point of actually using both together? Does not docker…
John
  • 4,786
  • 8
  • 35
  • 44
131
votes
3 answers

Cluster and Fork mode difference in PM2

I've searched a lot to figure out this question, but I didn't get clear explanation. Is there only one difference thing that clustered app can be scaled out and forked app cannot be? PM2's public site explains Cluster mode can do these feature but…
Jinyoung Kim
  • 1,885
  • 3
  • 14
  • 23
119
votes
9 answers

How to add dates to pm2 error logs?

Is there a way to add timestamps to error logs in .pm2/logs? I noticed that pm2 logs command shows aggregated logs with timestamps, but looking into log files - there are only messages and stacktraces without dates.
Plastic Rabbit
  • 2,859
  • 4
  • 25
  • 27
104
votes
11 answers

How to pass execution arguments to app using PM2?

I am using pm2 to start my app but I'm not able to pass argument to it. The command I am using is pm2 start app.js -- dev. Though this works with forever.
user3373581
  • 1,141
  • 2
  • 7
  • 11
75
votes
2 answers

What is the purpose of "pm2 save"?

I am using pm2 to manage my node.js processes. Very happy with it so far. What is the purpose of $ pm2 save? What is the purpose of saving a process list? I don't quite understand from the documentation. https://github.com/Unitech/pm2
guagay_wk
  • 26,337
  • 54
  • 186
  • 295
74
votes
1 answer

What is the difference between pm2 restart and pm2 reload

I have a nodejs app running on server. When should I use pm2 restart,and when should pm2 reload be used? Referred to the pm2 documention here,but couldn't figure out the difference in use case of the two.
Ayan
  • 8,192
  • 4
  • 46
  • 51
70
votes
8 answers

How to kill the pm2 --no-daemon process

I'm using pm2 as the process manager of Node.js. In many cases, I think I will run it as a daemon process, but if you use it locally as debugging, I think that there are times when you use the --no-daemon option. How do I end the process when moving…
Junya Kono
  • 1,121
  • 3
  • 10
  • 16
68
votes
3 answers

rename process using pm2 programmatic api

I have an electron app which uses pm2 to start some apps using the pm2 module.Everything is fine.However I am trying to implement the following feature:Renaming an app you have started.I know that using the cli I can do the following: pm2 restart…
Manos Kounelakis
  • 2,848
  • 5
  • 31
  • 55
62
votes
5 answers

What is the default location of PM2 log files?

I'm trying to find out where PM2 saves the log files by default? I'm working with a Linux Ubuntu 16.04 server and I've installed it globally with npm i pm2 -g.
Dave
  • 1,912
  • 4
  • 16
  • 34
61
votes
7 answers

Make pm2 log to console

I am running a node webserver using pm2. Since pm2 spawns another process and redirects stdout and stderr to files, I have to look somewhere else for the logs. Ideally, I would like to have the node process output to the same console window that…
Fragilerus
  • 1,829
  • 3
  • 15
  • 22
60
votes
4 answers

How do I delete/flush pm2 logs for only one app?

Can I flush the logs of only one app in Pm2? Assuming my app id is 2 I tried pm2 flush 2 but still it flushes all apps' logs.
Ali Elkhateeb
  • 3,413
  • 4
  • 21
  • 39
54
votes
8 answers

How to make a task job with PM2?

I want to make a repeatable job to send mail every 15 minutes taking data from a database table. In node js I can create the job but through PM2 I don't understand where to place the code and how it works.
Milan Mahata
  • 599
  • 1
  • 6
  • 12
50
votes
6 answers

Does pm2 auto restart application after reboot by default?

I have an issue with my linux server and need to reboot, before that I run my node application with pm2 start server.js without any other config. Can it auto restart my app after reboot server?
Andy Nguyen
  • 863
  • 1
  • 8
  • 20
1
2 3
99 100