{"id":19467344,"url":"https://github.com/cevio/ipc-message","last_synced_at":"2026-05-16T09:10:17.904Z","repository":{"id":57276517,"uuid":"115012299","full_name":"cevio/ipc-message","owner":"cevio","description":"It is an interactive class based on the process communication between `master`, `Worker` and `Agent`.","archived":false,"fork":false,"pushed_at":"2018-01-10T12:06:22.000Z","size":15,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T05:15:54.759Z","etag":null,"topics":["agent","child-process","cluster","ipc","ipc-message"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cevio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-21T14:06:33.000Z","updated_at":"2018-01-26T10:08:53.000Z","dependencies_parsed_at":"2022-09-13T04:42:41.545Z","dependency_job_id":null,"html_url":"https://github.com/cevio/ipc-message","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevio%2Fipc-message","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevio%2Fipc-message/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevio%2Fipc-message/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevio%2Fipc-message/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cevio","download_url":"https://codeload.github.com/cevio/ipc-message/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240680827,"owners_count":19840314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","child-process","cluster","ipc","ipc-message"],"created_at":"2024-11-10T18:34:41.383Z","updated_at":"2026-05-16T09:10:12.866Z","avatar_url":"https://github.com/cevio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IPC Message\n\nIt is an interactive class based on the process communication between `master`, `Worker` and `Agent`.\n\n# Install\n\n```bash\nnpm install --save ipc-message\n```\n\n# Usage\n\n```javascript\nconst IPCMessage = require('ipc-message');\nmodule.exports = class NodeBase extends IPCMessage {\n  constructor() {\n    // If it is a `agent` type process, you need to set the parameter to `true`. \n    // super(true);\n    super();\n\n    // receive message from other processes.\n    this.on('message', msg =\u003e {\n      console.log(`[${this.type}] Receive Message:`, msg);\n    });\n\n    if (this.type === 'master') {\n      // do master ...\n    } else {\n      // do worker\n    }\n  }\n}\n```\n\n# Receive Message Event\n\nWe can receive messages from other processes through the event `message`.\n\n```javascript\nconst IPCMessage = require('ipc-message');\nmodule.exports = class NodeBase extends IPCMessage {\n  constructor() {\n    super();\n    this.on('message', msg =\u003e {\n      console.log(`[${this.type}] Receive Message:`, msg);\n    });\n  }\n}\n```\n\n# Send Message Function\n\nWe send data through the `send` method.\n\n```javascript\nthis.send(to, action, data);\n```\n\nIntroduction of parameters:\n\n- **to** `Array|String|Number` Which process to send data to: `master` `workers` `agents` `*` \n- **action** `String` Data identification\n- **data** `*` data body\n\nWhen we send data through the subprocess or the `Agent` process, the `master` process is transferred. For example, if we want to send the `Agent` process to the sub process, we will first send it to the `Agent` process through the `master` process, and vice versa.\n\n# Regist Agent\n\n```javascript\nconst agentWorkerRuntimeFile = path.resolve(__dirname, 'agent.js');\nconst agent = ChildProcess.fork(agentWorkerRuntimeFile, null, {\n  cwd: process.cwd(),\n  stdout: process.stdout,\n  stderr: process.stderr,\n  stdin: process.stdin,\n  stdio: process.stdio\n});\nthis.registAgent('agentname', agent);\n```\n\n**this.registAgent(agentname, agentobject)**\n\n- **agentname** `String` The name of `Agent`.\n- **agentobject** `Object` Agent object.\n\nNo matter how many `Agent` processes you open, you must use this method to register. This method will automatically bind the logic of sending and receiving messages from Agent.\n\n# Test\n\nYou can see how to write through the examples in the test folder, and you can test the class by using the `npm run test` command.\n\n## License\n\nIPC Message is [MIT licensed](https://opensource.org/licenses/MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcevio%2Fipc-message","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcevio%2Fipc-message","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcevio%2Fipc-message/lists"}