LearnBoost Cluster Manager
This `cluster` package, developed by LearnBoost, is an extensible multi-core server manager for Node.js applications, last released as version 0.7.7. It was created to provide advanced process management features such as zero-downtime restarts, graceful shutdowns, worker resuscitation, and configurable worker counts (defaulting to CPU cores), during a period when the native Node.js `cluster` module was either unavailable or less feature-rich (specifically, between Node.js v0.4 and v0.8). The library offers a robust plugin system, including built-in plugins for command-line interfaces, debugging, logging, PID file management, automatic reloads, and REPL-based administration. Despite its innovative features for its time, the project is considered abandoned, with the last substantial development activity over a decade ago and official support for only very old Node.js versions (0.2.x, 0.4.x). It does not function with contemporary Node.js runtimes, making it a historical artifact rather than a viable solution for modern applications.
Common errors
-
TypeError: cluster is not a function
cause This error often occurs when `require('cluster')` resolves to Node.js's built-in `cluster` module instead of the LearnBoost package, as the native module does not export a top-level function for initialization.fixIf intending to use the LearnBoost package, ensure it is correctly installed and that the module resolver picks it up. However, due to its abandonment, the recommended fix is to migrate to Node.js's native `cluster` module, which has a different API. -
Error: Cannot find module 'cluster'
cause The package was not installed or is not resolvable from the current working directory, or the `npm install cluster` command failed.fixRun `npm install cluster`. If the issue persists, verify your `node_modules` directory and Node.js environment. (Note: This package is not recommended for new projects). -
Segmentation fault (core dumped) or similar native crashes with modern Node.js.
cause The LearnBoost `cluster` package makes low-level assumptions about the Node.js internal API and C++ bindings that are fundamentally incompatible with modern Node.js runtime changes.fixThis package is incompatible with modern Node.js. There is no fix to make this package work on recent Node.js versions. You must migrate to Node.js's native `cluster` module or other modern process management solutions.
Warnings
- breaking This package is abandoned and incompatible with modern Node.js versions (e.g., Node.js 6.x and above). It was last updated for Node.js 0.2.x and 0.4.x. Attempting to use it will result in runtime errors or unexpected behavior.
- gotcha The package name `cluster` directly conflicts with Node.js's built-in `cluster` module. Importing `require('cluster')` might load the native module instead of this third-party package if not installed or resolved carefully, leading to API mismatches and errors.
- security As an abandoned package with no updates for over a decade, `LearnBoost/cluster` has not received security patches for known vulnerabilities in Node.js or its dependencies. Using it in production could expose applications to significant security risks.
Install
-
npm install cluster -
yarn add cluster -
pnpm add cluster
Imports
- cluster
import cluster from 'cluster';
const cluster = require('cluster'); - Master
import { Master } from 'cluster';const Master = require('cluster').Master; - cluster('app')
const cluster = require('cluster'); cluster('./app').listen(3000);const serverApp = require('./app'); const clusterManager = require('cluster'); clusterManager(serverApp).listen(3000);
Quickstart
const http = require('http');
const cluster = require('cluster');
// app.js (or inline server definition)
const app = http.createServer(function(req, res){
console.log('Worker %s handling request for %s %s', process.pid, req.method, req.url);
const body = 'Hello World from worker ' + process.pid;
res.writeHead(200, { 'Content-Length': Buffer.byteLength(body) });
res.end(body);
});
// server.js (main cluster entry point)
if (require.main === module) {
cluster(app)
.use(cluster.logger('logs')) // Example plugin: logs master/worker activity
.use(cluster.stats()) // Example plugin: adds real-time statistics
.use(cluster.pidfiles('pids')) // Example plugin: writes master/worker pidfiles
.use(cluster.cli()) // Example plugin: provides a command-line interface
.use(cluster.repl(8888)) // Example plugin: real-time administration via REPL
.listen(3000, function(){
console.log('Cluster listening on port 3000, with %d workers', cluster.workers.length);
});
console.log('Master process %s started.', process.pid);
} else {
// When required by the master, just export the app
module.exports = app;
}