{"size": 1060, "ext": "js", "max_stars_repo_path": "hello-log4js/intercom.js", "max_stars_repo_name": "twotwo/practice-nodejs", "max_stars_repo_stars_event_min_datetime": "2018-12-28T04:15:19.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-28T04:15:19.000Z", "max_issues_repo_path": "hello-log4js/intercom.js", "max_issues_repo_name": "twotwo/practice-nodejs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hello-log4js/intercom.js", "max_forks_repo_name": "twotwo/practice-nodejs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.6326530612, "max_line_length": 75, "alphanum_fraction": 0.5811320755}
/**
 * pm2 install pm2-intercom
 * pm2 start intercom.js -n test-intercom
 */

const debug = require("debug")("pm2-tester")
debug.enable = true

process.on("message", function(packet) {
  if (packet.topic == "log4js:message") {
    console.log("Received packet", packet.data)
  }
})

//sender
var pm2 = require("pm2")
var neighborIds = []

pm2.connect(() => {
  // Find the IDs of who you want to send to
  pm2.list((err, processes) => {
    for (var i in processes) {
      // console.log("Id:", processes[i].pm_id, "Name:", processes[i].name)
      if (processes[i].name === "test-intercom") {
        neighborIds.push(processes[i].pm_id)
      }
    }

    // Call this once for each neighborIds
    pm2.sendDataToProcessId(
      neighborIds,
      {
        data: {
          some: "data"
        },
        topic: "log4js:message"
      },
      function(err, res) {
        console.log(err, res)
      }
    )
    console.log("Ids to send messages to:", neighborIds)
  })
})

setTimeout(() => {
  console.log("All done, shutdown cb returned.")
}, 5000)
