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
27
votes
3 answers

Restart pm2 app every 12h with cron

Tried this, but it doesn't work: SHELL=/bin/bash PATH=/usr/lib/node_modules/pm2/bin * 0,12 * * * pm2 restart all What am I doing wrong?
Nitor
  • 401
  • 1
  • 4
  • 8
26
votes
5 answers

How should I use pm2 command for npm run dev

I'm running my app using sudo npm run dev how should I use pm2 in order to run sudo npm run dev this command.
Asmita Bhiware
  • 383
  • 1
  • 3
  • 9
25
votes
3 answers

How can I get pm2 to use my ecosystem.config.js file on reboot?

My ecosystem.config.js file loads my environment great with this command: pm2 start ecosystem.config.js When I run any of these command, my environment is reloaded just fine: pm2 reload myapp pm2 restart myapp pm2 reload ecosystem.config.js pm2…
nomad
  • 1,699
  • 5
  • 21
  • 35
24
votes
2 answers

PM2 process disappears after reboot

I am using PM2 to run my node app as a service. My Node app is RAM Hungry so it consumes around 300 to 800mb of ram depending on traffic. My DigitalOcean droplet has 1GB RAM. Sometimes out of the blue, my app disappears from running services and I…
Usman Tahir
  • 2,513
  • 4
  • 24
  • 38
24
votes
3 answers

Expressjs pm2 ignore watch public/images folder

I have a website using nodejs. Problem is when user upload images the site stop working. That because of PM2 restart server when file change I think. How to solve this problem. thank you
Vuong Tran
  • 466
  • 1
  • 4
  • 12
24
votes
4 answers

How to automatically reload Node.js project when using pm2

I am currently programming Node.js with Express.js, and every time I change a line of code in the file router or app, I need to type the command: pm2 reload id_project. How do I make pm2 auto-reload the project when a file is changed?
Mr.Dung
  • 333
  • 1
  • 3
  • 10
23
votes
1 answer

Should You Use PM2, Node Cluster, or Neither in Kubernetes?

I am deploying some NodeJS code into Kubernetes. It used to be that you needed to run either PM2 or the NodeJS cluster module in order to take full advantage of multi-core hardware. Now that we have Kubernetes, it is unclear if one must use one or…
Randy L
  • 14,384
  • 14
  • 44
  • 73
23
votes
5 answers

Pm2 changing log file location

I have couple of questions regarding pm2 How can I change the location of server-error-0.log and server-out-0.log files location from c:\users\user\.pm2\logs to other drive, due to restriction in server's c drive access. Can I log the error and…
Jeet
  • 5,569
  • 8
  • 43
  • 75
23
votes
1 answer

Express 4 + pm2 watch not working

I'm running pm2 with this: pm2 start bin/www --watch ../ Problem is that when I update app.js in the root folder, it doesn't seem to be autorestarting node. Any ideas?
ninjaneer
  • 6,951
  • 8
  • 60
  • 104
22
votes
1 answer

pm2 managed process in errored state after machine reboot

I'm using pm2 (version 3.4.1) to manage the Laravel Echo websocket server. It runs perfect, but I'm trying to get it to auto-start after a machine reboot (which runs Ubuntu 16.04). To do this I followed these instructions: $ pm2 startup [PM2] Init…
kramer65
  • 50,427
  • 120
  • 308
  • 488
22
votes
1 answer

Show pm2 command that started a process

From my linux machine, typing pm2 status shows me │ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │ ├──────────────┼────┼──────┼───────┼─────────┼─────────┼────────┼─────────────┼──────────┤ │ gamatrix-dev │…
John
  • 32,403
  • 80
  • 251
  • 422
22
votes
5 answers

How to start node.js app with pm2 in cluster mode?

We are trying to start our app with pm2 0.12.8 on ubuntu 14.04 with octa core proccessor. The read me on the git hub has a very straight forward command for running node app in cluster mode. # Cluster mode $ pm2 start app.js -i 0 **# Will…
Hitu Bansal
  • 2,917
  • 10
  • 52
  • 87
22
votes
4 answers

How to pass node v8 args and script args to pm2?

I need to be able to start the app below with pm2 but don't know how to start it with pm2. node --expose-gc bin/www arg1 arg2 arg3 I know about --node-args but I think is only for --expose-gc.
Rodrigo Pereira
  • 1,834
  • 2
  • 17
  • 35
21
votes
2 answers

How to write JSON file using Bash?

I'd like to write a JSON file using BASH but it seem's not working well.. My code : sudo echo -e "Name of your app?\n" sudo read appname sudo cat "{apps:[{name:\"${appname}\",script:\"./cms/bin/www\",watch:false}]}" > process.json Issue : -bash:…
tonymx227
  • 5,293
  • 16
  • 48
  • 91
21
votes
6 answers

pm2 - How to start if not started, kill and start if started

I am trying to start pm2 if it is not running, or kill it and start if it is, how can I achieve this behavior in the WINDOWS command line interface? There are plenty of solutions using grep in linux but nothing for windows, any idea on how to get…