{"id":27753,"library":"forky","title":"forky","description":"Forky (v1.2.0) simplifies Node.js cluster management by automatically forking workers equal to the number of CPU cores. It auto-restarts crashed workers and supports graceful shutdown via the `suicide` flag. Unlike alternatives like `pm2` or `cluster` alone, forky is lightweight, zero-config for basic setups, and keeps the worker code unmodified. It ships TypeScript types and is suitable for Node >=8. Development appears stale (last commit 2019); no major release since.","status":"maintenance","version":"1.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/brianc/node-forky","tags":["javascript","cluster","pre-fork","typescript"],"install":[{"cmd":"npm install forky","lang":"bash","label":"npm"},{"cmd":"yarn add forky","lang":"bash","label":"yarn"},{"cmd":"pnpm add forky","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CJS require works too; package supports CommonJS.","wrong":"const forky = require('forky')","symbol":"default","correct":"import forky from 'forky'"},{"note":"TypeScript type import; requires TS 3.8+","symbol":"ForkyOptions","correct":"import type { ForkyOptions } from 'forky'"},{"note":"The default export is a function that takes a ForkyOptions object.","wrong":"forky() without options","symbol":"default function call","correct":"import forky from 'forky';\nforky({ path: './worker.js' })"}],"quickstart":{"code":"import forky from 'forky';\nimport http from 'http';\n\n// Worker (worker.js)\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('Hello from worker ' + process.pid);\n});\nserver.listen(8000);\n\n// Graceful shutdown on uncaught exception\nprocess.on('uncaughtException', (err) => {\n  console.error(err);\n  process.disconnect();\n});\n\n// Master (master.js) - run with: npx ts-node master.ts\nforky({ path: './worker.js' });","lang":"typescript","description":"Shows basic forky usage: master forking workers from a separate file, worker with HTTP server and graceful shutdown."},"warnings":[{"fix":"Ensure the path is absolute or resolved correctly relative to the master process.","message":"If the worker file is not found or cannot be loaded, forky will exit with an unhandled error.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use `worker.exitedAfterDisconnect` instead.","message":"The `suicide` property on worker objects is deprecated in Node.js and will be removed.","severity":"deprecated","affected_versions":">=1.0"},{"fix":"Implement custom signal handlers in the master process to disconnect workers.","message":"Forky does not handle SIGTERM/SIGINT propagation; workers may not shut down cleanly on process exit.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Add error handling or a max restarts limit via process.on('uncaughtException') in workers.","message":"If all workers crash immediately (e.g., due to a syntax error in worker code), forky will loop infinitely restarting them.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use `process.send()` and `cluster.on('message')` as documented.","message":"Forky does not support IPC messaging between master and workers beyond the built-in cluster messaging.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use __dirname + '/worker.js' or an absolute path.","cause":"The path provided to forky is relative to the working directory, not the master script.","error":"Error: Cannot find module './worker.js'"},{"fix":"Have each worker listen on a different port (e.g., 8000 + worker.id) or use a reverse proxy.","cause":"Multiple workers trying to bind to the same port; worker code should not call server.listen() directly when master forks multiple.","error":"Error: listen EADDRINUSE :::8000"},{"fix":"Use `import forky from 'forky'` or `const forky = require('forky')`.","cause":"Importing the module incorrectly, e.g., using named import when only default export exists.","error":"TypeError: forky is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}