Search code examples
node.jspm2

Is it possible to get the process metadata from PM2?


I was wondering if it was possible to get process metadata using pm2 inside my node application.

enter image description here


Solution

  • Yes, you can get any information from pm2 inside your app. below will return all running process list. For further details, you can check pm2-api

    var pm2 = require('pm2');
    app.use('/all_process_list', function(req,res){
    
      pm2.connect(function(err) {
        if (err) {
          console.error(err);
          process.exit(2);
        }
        pm2.list(function(err, processDescriptionList) {
          console.log(processDescriptionList)
          res.json ({process_list:processDescriptionList})
          pm2.disconnect();   // Disconnects from PM2
    
        });
      });   
    });