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

How do I set Linux environment variables so that pm2 can see them for node.js apps?

When I run my nodejs application on my Ubuntu Linux server using node server.js it works correctly, and outputs the value of the environment variable $db using process.env.db. However, the app breaks when running sudo pm2 start server.js, seeing the…
Richard
  • 14,798
  • 21
  • 70
  • 103
7
votes
1 answer

pm2 graceful restart to improve user experience and avoid problems

Is there a way to do a graceful restart of pm2 for all nodejs processes? I'm looking for something similar to Apache's graceful restart. Want to avoid killing a server execution in progress for every code deployment.
steampowered
  • 11,809
  • 12
  • 78
  • 98
7
votes
1 answer

Start application with pm2 if starts form gulp

Hi I was following a tutorial to build an nodejs app. This tutorial is using gulp, to run my app I just do gulp dev to start all things. In my gulpfile I have: var fs = require('fs') var gulp =…
Alex
  • 579
  • 5
  • 24
7
votes
6 answers

PM2 - Autostart on Raspbian (Raspberry Pi) does not work

Ok guys, this is driving me nuts... Can't get my nodejs application to autostart@boot on a raspberry pi... Machine: Raspberry 2 (Raspbian Jessie) Tried almost every possible solution I found on Google. This is what I've ended up with: Installed…
Sascha
  • 581
  • 1
  • 4
  • 19
7
votes
2 answers

How to deploy with PM2 and Grunt

I am using angular-fullstack for my application. I want to start my apps using pm2. Angular-fullstack starts prodcution mode by grunt serve:dist, it runs several tasks including setting environment variables. PM2 seems to start an application with…
Wint
  • 2,268
  • 2
  • 22
  • 32
7
votes
1 answer

Node.js, pm2, and sticky sessions – possible?

Is there a way to have sticky sessions with node module pm2? I'm aware that they were intentionally left out of node's internal cluster module, and so it might not be the best architecture choice with Node.js to begin with. However, in case of…
Ville
  • 4,088
  • 2
  • 37
  • 38
6
votes
2 answers

run pm2 with ES modules

How can i use pm2 in combination with a package based on ES Module (type:"module") I looked into similar Questions without any useful help (some say it does not work on windows, but i am using linux) I always receive the error: Error…
thompson
  • 179
  • 1
  • 12
6
votes
0 answers

Unexpected token '<' at Loader.moduleStrategy

I'm running a backend Express app and a React.JS app in one Docker container using PM2. My backend Nodejs Express app works fine, it's just the React app. I had an initial error of: Cannot use import statement outside a module which I was able to…
Nathan
  • 1,393
  • 1
  • 9
  • 40
6
votes
2 answers

How can I completely stop a pm2 managed application?

Say I have a pm2 process that runs every 5 minutes and takes less than a second to run: pm2 start ./some-node-script.js --name some-node-script --cron "*/5 * * * *" --no-autorestart Now say I want to completely stop execution of the job. If I issue…
AJ.
  • 16,368
  • 20
  • 95
  • 150
6
votes
2 answers

PM2 - Incorrect memory usage reading & possible memory leak with Node.js application

When my node js server is running via pm2, it has a higher memory usage reading than the actual memory heap in the application when inspected in DevTools. More so, the value under memory in pm2 slowly increases over time, possibly indicating some…
user2993497
  • 525
  • 1
  • 7
  • 21
6
votes
2 answers

How to run a python3 script with pm2

Pm2 default start command runs a script using python2. How can I make it run a script using python3 ? Let us say my script is called app.py .
Cap Barracudas
  • 2,347
  • 4
  • 23
  • 54
6
votes
1 answer

Docker exits with code 0 when using pm2 start

My Dockerfile contains the pm2 start command as follows: FROM node:10 WORKDIR /usr/src/app COPY . . # ... EXPOSE 8080 CMD [ "pm2", "start", "npm", "--", "start" ] However the container exits straightaway after pm2 logs successfully…
sdgluck
  • 24,894
  • 8
  • 75
  • 90
6
votes
3 answers

Not able to run typescript node.js app with ts-node with pm2

I have created a basic node app with typescript top of it. I am using ts-node to do so and it's working totally fine with nodemon. But I need to move it to the server now I am stuck. PM2 is showing error all the time. I have gone through GitHub and…
Shailesh Jha
  • 1,122
  • 1
  • 8
  • 9
6
votes
1 answer

Issue with executing npm scripts via pm2 in Windows

I am trying to run npm custom scripts via pm2 using ecosystem.json as, { "apps": [{ "name": "Service", "script": "npm", "args": "run command" }] } Unfortunately I am unable to do it. Can anyone help me to get through…
6
votes
2 answers

Using PM2 to run other npm scripts

In my package.json file I have two scripts, start and production, start script is for local development while production script is for deployment. Using npm i would just do npm run production but how do I do this with pm2
lulliezy
  • 1,741
  • 5
  • 24
  • 49