Registry / devops / forky
library1.2.0jsnpmunverified

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.

npm install forky
INSTALL
IMPORT
SIG · FORKY
F
forky
devopsjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import forky from 'forky'
const forky = require('forky')
CJS require works too; package supports CommonJS.
ForkyOptions
import type { ForkyOptions } from 'forky'
TypeScript type import; requires TS 3.8+
default function call
import forky from 'forky'; forky({ path: './worker.js' })
forky() without options
The default export is a function that takes a ForkyOptions object.

Shows basic forky usage: master forking workers from a separate file, worker with HTTP server and graceful shutdown.

import forky from 'forky'; import http from 'http'; // Worker (worker.js) const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello from worker ' + process.pid); }); server.listen(8000); // Graceful shutdown on uncaught exception process.on('uncaughtException', (err) => { console.error(err); process.disconnect(); }); // Master (master.js) - run with: npx ts-node master.ts forky({ path: './worker.js' });
Debug
Known issues
gotchaIf the worker file is not found or cannot be loaded, forky will exit with an unhandled error.
fix
Ensure the path is absolute or resolved correctly relative to the master process.
affects: >=1.0
deprecatedThe `suicide` property on worker objects is deprecated in Node.js and will be removed.
fix
Use `worker.exitedAfterDisconnect` instead.
affects: >=1.0
gotchaForky does not handle SIGTERM/SIGINT propagation; workers may not shut down cleanly on process exit.
fix
Implement custom signal handlers in the master process to disconnect workers.
affects: >=1.0
gotchaIf all workers crash immediately (e.g., due to a syntax error in worker code), forky will loop infinitely restarting them.
fix
Add error handling or a max restarts limit via process.on('uncaughtException') in workers.
affects: >=1.0
gotchaForky does not support IPC messaging between master and workers beyond the built-in cluster messaging.
fix
Use `process.send()` and `cluster.on('message')` as documented.
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module './worker.js'
The path provided to forky is relative to the working directory, not the master script.
fix
Use __dirname + '/worker.js' or an absolute path.
Error: listen EADDRINUSE :::8000
Multiple workers trying to bind to the same port; worker code should not call server.listen() directly when master forks multiple.
fix
Have each worker listen on a different port (e.g., 8000 + worker.id) or use a reverse proxy.
TypeError: forky is not a function
Importing the module incorrectly, e.g., using named import when only default export exists.
fix
Use `import forky from 'forky'` or `const forky = require('forky')`.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
forky — npm install forky · libregistry