{"name":"cfork","version":"2.0.0","description":"cluster fork and restart easy way","homepage":"https://github.com/node-modules/cfork","repository":{"type":"git","url":"git://github.com/node-modules/cfork.git"},"bugs":{"url":"https://github.com/node-modules/cfork/issues"},"keywords":["cluster","cluster-fork","cfork","restart"],"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"},"license":"MIT","engines":{"node":">= 18.19.0"},"dependencies":{"utility":"^2.2.0"},"devDependencies":{"@arethetypeswrong/cli":"^0.17.1","@eggjs/tsconfig":"1","@types/mocha":"10","@types/node":"22","egg-bin":"6","eslint":"8","eslint-config-egg":"14","graceful":"^2.0.0","tshy":"3","tshy-after":"1","typescript":"5","urllib":"^4.6.8"},"scripts":{"lint":"eslint --cache src test --ext .ts","pretest":"npm run lint -- --fix && npm run prepublishOnly","test":"egg-bin test","preci":"npm run lint && npm run prepublishOnly","ci":"egg-bin cov","prepublishOnly":"tshy && tshy-after && attw --pack"},"type":"module","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"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"},"types":"./dist/commonjs/index.d.ts","main":"./dist/commonjs/index.js","module":"./dist/esm/index.js","_id":"cfork@2.0.0","gitHead":"8ec28fcb6a221abeb4bd4ae9b01e38e3de22b40b","_nodeVersion":"18.20.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-J7u2GSj77TRvJmEfBL4ln5TROEka6X5tEOKF6qe6kritcltmrbmeiP2p9A2EA1dGOxR5UX7H804ByzIZAM+Nqg==","shasum":"41ec5c2d5eae0605468aec3cbd6a456c1ee092fe","tarball":"http://registry-npm.ywwl.com/cfork/download/cfork-2.0.0.tgz","fileCount":11,"unpackedSize":72793,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/cfork@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDDq1C1KPM834KL857fC4ttaqrerjQESKxSF9OMyekpoAiEAhgUfWIVN86G/w3BiQ72jO7V99ab9hDsOMZxxmmX/4Ik="}],"size":13756,"noattachment":false,"key":"/cfork/-/cfork-2.0.0.tgz"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"directories":{},"maintainers":[{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":"sakura9515@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cfork_2.0.0_1734261314242_0.8799837978595062"},"_hasShrinkwrap":false,"readme":"# cfork\n\n[![NPM version][npm-image]][npm-url]\n[![Node.js CI](https://github.com/node-modules/cfork/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/cfork/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/cfork.svg?style=flat)](https://nodejs.org/en/download/)\n\n[npm-image]: https://img.shields.io/npm/v/cfork.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/cfork\n[codecov-image]: https://codecov.io/gh/node-modules/cfork/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/node-modules/cfork\n[download-image]: https://img.shields.io/npm/dm/cfork.svg?style=flat-square\n[download-url]: https://npmjs.org/package/cfork\n\ncluster fork and restart easy way.\n\n* Easy fork with worker file path\n* Handle worker restart, even it was exit unexpected.\n* Auto error log process `uncaughtException` event\n\n## Install\n\n```bash\nnpm install cfork\n```\n\n## Usage\n\n### ESM and TypeScript\n\n```ts\nimport util from 'node:util';\nimport { cfork } from 'cfork';\n\nconst clusterWorker = cfork({\n  exec: '/your/app/worker.js',\n  // slaves: ['/your/app/slave.js'],\n  // count: require('os').cpus().length,\n}).on('fork', worker => {\n    console.warn('[%s] [worker:%d] new worker start', Date(), worker.process.pid);\n  })\n  .on('disconnect', worker => {\n    console.warn('[%s] [master:%s] wroker:%s disconnect, exitedAfterDisconnect: %s, state: %s.',\n      Date(), process.pid, worker.process.pid, worker.exitedAfterDisconnect, worker.state);\n  })\n  .on('exit', (worker, code, signal) => {\n    const exitCode = worker.process.exitCode;\n    const err = new Error(util.format('worker %s died (code: %s, signal: %s, exitedAfterDisconnect: %s, state: %s)',\n      worker.process.pid, exitCode, signal, worker.exitedAfterDisconnect, worker.state));\n    err.name = 'WorkerDiedError';\n    console.error('[%s] [master:%s] wroker exit: %s', Date(), process.pid, err.stack);\n  })\n  // if you do not listen to this event\n  // cfork will output this message to stderr\n  .on('unexpectedExit', (worker, code, signal) => {\n    // logger what you want\n  })\n  // emit when reach refork times limit\n  .on('reachReforkLimit', () => {\n    // do what you want\n  });\n\n// if you do not listen to this event\n// cfork will listen it and output the error message to stderr\nprocess.on('uncaughtException', err => {\n  // do what you want\n});\n\n// if you want to dynamically disable refork, you can call the setDisableRefork, priority over the refork parameter\ncfork.setDisableRefork(clusterWorker, true);\n```\n\n### CommonJS\n\n```js\nconst { cfork } = require('cfork');\n```\n\n### Options\n\n* **exec** : exec file path\n* **slaves** : slave process config\n* **args** : exec arguments\n* **count** : fork worker nums, default is `os.cpus().length`\n* **refork** : refork when worker disconnect or unexpected exit, default is `true`\n* **limit**: limit refork times within the `duration`, default is `60`\n* **duration**: default is `60000`, one minute (so, the `refork times` < `limit / duration`)\n* **autoCoverage**: auto fork with istanbul when `running_under_istanbul` env set, default is `false`\n* **env**: attach some environment variable key-value pairs to the worker / slave process, default to an empty object.\n* **windowsHide**: Hide the forked processes console window that would normally be created on Windows systems, default to false.\n* **serialization**: Specify the kind of serialization used for sending messages between processes. Possible values are 'json' and 'advanced'. See Advanced serialization for child_process for more details. Default: false.\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=node-modules/cfork)](https://github.com/node-modules/cfork/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1734261314414,"_cnpm_publish_time":1734261314414,"dist-tags":{"latest":"2.0.0"}}