Questions tagged [pm2]

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

Filter by
Sorted by
Tagged with
426 votes
23 answers
570k views

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'...
svnm's user avatar
  • 23.7k
176 votes
18 answers
169k views

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. ...
dreagan's user avatar
  • 2,436
150 votes
3 answers
92k views

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 ...
John's user avatar
  • 5,056
136 votes
3 answers
117k views

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 ...
Jinyoung Kim's user avatar
  • 1,935
125 votes
9 answers
96k views

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 ...
Plastic Rabbit's user avatar
104 votes
11 answers
146k views

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's user avatar
  • 1,141
81 votes
2 answers
93k views

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 ...
guagay_wk's user avatar
  • 27.3k
78 votes
1 answer
65k views

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 ...
Ayan's user avatar
  • 8,520
75 votes
3 answers
73k views

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 ...
Manos Kounelakis's user avatar
74 votes
9 answers
212k views

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-...
Junya Kono's user avatar
  • 1,161
70 votes
6 answers
155k views

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's user avatar
  • 2,042
63 votes
4 answers
110k views

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's user avatar
62 votes
7 answers
139k views

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 ...
Fragilerus's user avatar
  • 1,839
60 votes
6 answers
78k views

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's user avatar
55 votes
8 answers
75k views

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 ...
Milan Mahata's user avatar
46 votes
3 answers
141k views

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 ...
Luke W's user avatar
  • 8,636
45 votes
4 answers
83k views

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 ...
Talespin_Kit's user avatar
  • 21.3k
44 votes
7 answers
57k views

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=/...
Nik Sumeiko's user avatar
  • 8,523
40 votes
3 answers
46k views

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 ...
Nawa's user avatar
  • 2,118
39 votes
4 answers
64k views

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/...
tree em's user avatar
  • 21k
39 votes
1 answer
28k views

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 ...
Ruan Kotovich's user avatar
37 votes
6 answers
89k views

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 ...
PabloDK's user avatar
  • 2,351
36 votes
2 answers
56k views

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 ...
Estus Flask's user avatar
35 votes
7 answers
59k views

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's user avatar
35 votes
2 answers
117k views

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 --...
ridermansb's user avatar
35 votes
5 answers
71k views

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 ...
Schmidko's user avatar
  • 740
35 votes
5 answers
65k views

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 ...
Coder_Nick's user avatar
35 votes
2 answers
14k views

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 ...
llf's user avatar
  • 483
33 votes
5 answers
73k views

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) ...
hwoarangzk's user avatar
31 votes
2 answers
40k views

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 ...
Usman Tahir's user avatar
  • 2,623
30 votes
6 answers
52k views

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.
Rubi Pandey's user avatar
30 votes
6 answers
42k views

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 ...
narad's user avatar
  • 509
29 votes
6 answers
63k views

Can I use pm2 to keep a Next.js app running

I have an AWS EC2 that is just for keeping my Next.js client side running (there is no backend for it right now). Currently if I go into the terminal and enter npm run develop, the site runs perfectly....
optionalfigure's user avatar
29 votes
3 answers
44k views

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's user avatar
  • 421
27 votes
3 answers
59k views

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 ...
nomad's user avatar
  • 1,728
25 votes
3 answers
33k views

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's user avatar
24 votes
4 answers
34k views

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-...
Mr.Dung's user avatar
  • 333
23 votes
5 answers
47k views

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. # ...
Hitu Bansal's user avatar
  • 3,017
23 votes
5 answers
55k views

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 ...
Jeet's user avatar
  • 5,629
23 votes
1 answer
28k views

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's user avatar
  • 6,991
23 votes
2 answers
110k views

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\"...
tonymx227's user avatar
  • 5,401
23 votes
6 answers
28k views

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 ...
Bryan Arbelo - MaG3Stican's user avatar
23 votes
3 answers
63k views

Run Typescript application with PM2

I have an application written in Typescript that runs with PM2. Currently I compile to JavaScript, then use PM2 to start the app. My ecosystem.config.js file looks like this: module.exports = { ...
CaribouCode's user avatar
  • 14.2k
23 votes
1 answer
11k views

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 ...
Randy L's user avatar
  • 14.5k
23 votes
1 answer
16k views

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 │ ├──────────────┼────┼──────┼───────┼─────────┼─────────┼──...
learningtech's user avatar
22 votes
4 answers
25k views

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's user avatar
22 votes
1 answer
4k views

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 ...
kramer65's user avatar
  • 52.2k
21 votes
4 answers
22k views

Running NodeJs http-server forever with PM2

My question is about running HTTP-server in combination with PM2. The problem I face is that: HTTP-server requires as input a folder which is the root of the website and a port number to run the ...
Guy Hagemans's user avatar
20 votes
5 answers
26k views

PM2 (Node.js) not listening on specified port

I am trying to get a Node/Express application up and running on PM2. I can start the application fine with this command: npm start This starts the app fine on port 3000. If I try to start the ...
JamesE's user avatar
  • 3,883
20 votes
3 answers
25k views

Reload PM2 configuration file

I have problems with reloading PM2 configuration file after editing it: { "apps": [ ... { "name": "foo", "script": "foo/index.js", "cwd": "foo",...
Estus Flask's user avatar

1
2 3 4 5
47