Process Actions

Process Actions

By plugging process actions onto your code, you will be able to trigger them via the PM2 CLI.

First make sure you add the library pmx to your code:

$ npm install pmx --save

Then in your code:

var pmx = require('pmx');

pmx.action('hello', function(reply) {
  reply({ answer : 'world' });

setInterval(function() {
  // Keep application online
}, 100);

Start the application with PM2 and now to trigger process actions, use the command:

$ pm2 trigger <application-name> <action-name>

process actions

You can also list all available process actions:

$ pm2 show <application-name>

process actions

Passing a parameter

To pass a parameter to the remote function, just add the param attribute to the callback:

var pmx = require('pmx');

pmx.action('world', function(param, reply) {
  reply({success : param});

Restart your application and call this process function with PM2:

$ pm2 trigger <application-name> <action-name> [parameter]