{"name":"sendmessage","version":"3.0.1","keywords":["sendmessage","send","cluster","message","channel closed"],"author":{"url":"https://github.com/fengmk2","name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"sendmessage@3.0.1","maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"}],"homepage":"https://github.com/node-modules/sendmessage","bugs":{"url":"https://github.com/node-modules/sendmessage/issues"},"dist":{"shasum":"85ffaecfdf14ef51832e0fb1ec914c4d59ea8795","tarball":"http://registry-npm.ywwl.com/sendmessage/download/sendmessage-3.0.1.tgz","fileCount":11,"integrity":"sha512-QiusxFoWDDXDm85aQ9E1WwB/votTPYNUSEKnCcmtRthMuqSuoULUmGfeuIdDPUmopzxbaDDRTq+9kPPB/nEc0g==","signatures":[{"sig":"MEYCIQCfSH658Wu3uz5fd4xpDhR3P7EtPrSbnHPV1rACAisfxAIhAMO5tXEIalV6JyZy6mH4ScaesuL2Yi/SehL2/iWGC5uX","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/sendmessage@3.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":17962,"size":4917,"noattachment":false,"key":"/sendmessage/-/sendmessage-3.0.1.tgz"},"main":"./dist/commonjs/index.js","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":">= 18.19.0"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"06c422d62aacae3a31e0dc46806e71dc6fea04a8","scripts":{"ci":"c8 -r lcov -r text -r text-summary npm test","lint":"eslint --cache src --ext .ts","test":"npm run lint && mocha --exit -t 5000 test/*.test.js","pretest":"npm run prepublishOnly && attw --pack","prepublishOnly":"tshy && tshy-after"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"repository":{"url":"git://github.com/node-modules/sendmessage.git","type":"git"},"_npmVersion":"10.8.2","description":"Send a cross process message if message channel is connected.","directories":{},"_nodeVersion":"18.20.5","_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.2","mm":"3","tshy":"^3.0.2","mocha":"^11.0.1","eslint":"8","tshy-after":"1","typescript":"5","@types/node":"22","@types/mocha":"10","@eggjs/tsconfig":"1","eslint-config-egg":"14","@arethetypeswrong/cli":"^0.17.1"},"_npmOperationalInternal":{"tmp":"tmp/sendmessage_3.0.1_1733910056773_0.526329280449904","host":"s3://npm-registry-packages-npm-production"},"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":1733910056979,"_cnpm_publish_time":1733910056979,"dist-tags":{"latest":"3.0.2"}}