{"name":"sendmessage","version":"2.0.0","keywords":["sendmessage","send","cluster","message","channel closed"],"author":{"url":"https://github.com/fengmk2","name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"sendmessage@2.0.0","homepage":"https://github.com/node-modules/sendmessage","bugs":{"url":"https://github.com/node-modules/sendmessage/issues","email":"fengmk2@gmail.com"},"dist":{"shasum":"d3eff19d12827addaae16eca7c9626a5d51dd2f2","tarball":"http://registry-npm.ywwl.com/sendmessage/download/sendmessage-2.0.0.tgz","fileCount":3,"integrity":"sha512-//UAqD/jhpCAQd4zRJ8KRv5FoaM2jeT94p+C2DlR0yGXZyjJTIQnl/fG7KpLo+x6tH+1SglUUh88C6LOxtaZbA==","signatures":[{"sig":"MEUCIAXMIkb2iAyEuSRyRZIq3YbNHDzfKEq8J8tVMZChdicXAiEA0w4kRbInZZv3fgbeEKu7dR05zQGTHftjxsTKhm9DB3g=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/sendmessage@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v0.2"}},"unpackedSize":6131,"size":2489,"noattachment":false,"key":"/sendmessage/-/sendmessage-2.0.0.tgz"},"main":"index.js","engines":{"node":">= 14.17.0"},"gitHead":"9edc58682d73ec937b0705f0274c1b679ebc26fe","scripts":{"ci":"c8 npm test","lint":"eslint .","test":"mocha --exit -t 5000 test/*.test.js"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"repository":{"url":"git://github.com/node-modules/sendmessage.git","web":"https://github.com/node-modules/sendmessage","type":"git"},"_npmVersion":"9.5.1","description":"Send a cross process message if message channel is connected.","directories":{},"_nodeVersion":"18.16.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"c8":"^7.14.0","mm":"^3.3.0","mocha":"^10.2.0","eslint":"^8.42.0","should":"*","eslint-config-egg":"^12.2.1"},"_npmOperationalInternal":{"tmp":"tmp/sendmessage_2.0.0_1686659887029_0.28618539299031753","host":"s3://npm-registry-packages"},"readme":"# sendmessage\n\n[![NPM version][npm-image]][npm-url]\n[![CI](https://github.com/node-modules/sendmessage/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/sendmessage/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/sendmessage.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/sendmessage\n[download-image]: https://img.shields.io/npm/dm/sendmessage.svg?style=flat-square\n[download-url]: https://npmjs.org/package/sendmessage\n[codecov-image]: https://codecov.io/gh/node-modules/sendmessage/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/node-modules/sendmessage\n\nSend a cross process message if message channel is connected.\nAvoid [channel closed](https://github.com/joyent/node/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/child_process.js#L411) error throw out.\n\n## Install\n\n```bash\nnpm install sendmessage --save\n```\n\n## Usage\n\n### master.js\n\n```ts\nimport { fork } from 'node:child_process';\nimport sendmessage from 'sendmessage';\n\nconst worker = fork('./worker.js');\n\nsendmessage(worker, { hi: 'this is a message to worker' });\n```\n\n### worker.js\n\n```ts\nimport sendmessage from 'sendmessage';\n\nsendmessage(process, { hello: 'this is a message to master' });\n```\n\n## API\n\n### #sendmessage(childProcess, message)\n\nSend a cross process message.\nIf a process is not child process, this will just call `process.emit('message', message)` instead.\n\n- childProcess: child process instance\n- message: the message need to send\n\n```js\nsendmessage(process, { hello: 'this is a message to master' });\n```\n\nYou can switch to `process.emit('message', message)` using `process.env.SENDMESSAGE_ONE_PROCESS`\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=node-modules/sendmessage)](https://github.com/node-modules/sendmessage/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1686659887207,"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"}],"_cnpm_publish_time":1686659887207,"dist-tags":{"latest":"3.0.2"}}