PM2

PM2 – Quick Start

Welcome to the PM2 Quick Start! PM2 is a daemon process manager that will help you manage and keep your application online. Getting started with PM2 is straightforward, it is offered as a simple and intuitive CLI, installable via NPM. Installation The latest PM2 version is installable with NPM or Yarn: $ npm install pm2@latest -g # or $ yarn global add pm2 To install Node.js and NPM you can use NVM Start an app The simplest way to start, daemonize and monitor your application is by using this...

Read more...

PM2 – Managing applications states

PM2 is a process manager. It manages your applications states, so you can start, stop, restart and delete processes. Start a process: pm2 start app.js --name "my-api" pm2 start web.js --name "web-interface" Now let’s say you need to stop the web-interface: pm2 stop web-interface As you can see the process hasn’t disappeared. It’s still there but in stopped status. To restart it just do: pm2 restart web-interface NB: starting PM2 2.1.x, restarts are immutable, meaning that environment changes will not change your process, see –update-env Now you want to delete the app from the PM2 process list....

Read more...

PM2 Simple deploy

Getting started PM2 embeds a simple and powerful deployment system with revision tracing. Another step by step tutorial here. Please read the Considerations to use PM2 deploy. Simple deploy Baically you only need to add a “deploy” attribute to the ecosystem.json. Here is a bare minimum to deploy an application: process.json: { "apps" : [{ "name" : "HTTP-API", "script" : "http.js" }], "deploy" : { // "production"...

Read more...

Updating PM2

To get the most out of PM2 and PM2.io, please make sure your PM2 version is up-to-date. You can find the changelog here: https://github.com/Unitech/pm2/releases. Updating PM2 Updating PM2 is extremely fast (less than few seconds) and seamless. First make sure that you saved correctly all your processes: pm2 save Then install the latest PM2 version from NPM: npm install pm2 -g And finally update the in-memory PM2 process: pm2 update That’s all, you now have a fresh and up-to-date PM2 system! Updating Startup Script When you upgrade your Node.js version, the node binary...

Read more...

PM2 Max Memory Threshold Auto Reload

Max Memory Threshold Auto Reload PM2 allows to reload (auto fallback to restart if not in cluster) an application based on a memory limit/ Please note that the PM2 internal worker (which checks memory), starts every 30 seconds, so you may have to wait a bit before your process gets restarted automatically after reaching the memory threshold. CLI: pm2 start api.js --max-memory-restart 300M Config file (ecosystem.config.js): module.exports = { apps: [{ name: 'api', script: 'api.js', ...

Read more...