
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
express-cluster
Advanced tools
Run an express server on multiple processes. This is meant to be dropped in directly to your main entry point without having to setup a separate script that manages workers.
This works with any EventListener that emits the "close"
event and has a
close()
method. If it's a server object (e.g. an express app, net.Server
or
http.Server
, ensure that you've invoked listen
before returning it).
By default the module will spawn os.cpus().length
workers. You should
configure this parameter for your workloads. You should pick the right number
for your server based on testing.
var express = require('express');
var cluster = require('express-cluster');
cluster(function(worker) {
var app = express();
app.get('/', function(req, res) {
res.send('hello from worker #' + worker.id);
});
return app.listen(0xbeef);
}, {count: 5})
express-cluster exports itself as a function that accepts config
and
workerFunctions
as arguments. These can be provided in either order:
cluster(config, workerFunction)
or cluster(workerFunction, config)
.
Once node executes cluster()
the current process will be forked the specified
number of times. You should guard any code that should only be run in the
master behind a check of process.env.NODE_UNIQUE_ID
or a call to node's
cluster.isMaster
workerFunction
This function is passed a worker
object. See the node documentation for
Worker for details.
config
This object should contain zero or more of these keys. Any other key/values are ignored.
{
count: 5, // number of workers: defaults to os.cpus().length
respawn: true, // respawn process on exit: defaults to true
verbose: false, // log what happens to console: defaults to false
// Attach the given function to each spawned worker. The function will
// be bound to the worker that sent the message so you can setup a two
// way message bus if you please. See examples/messaging.js for an
// example.
workerListener: function(){},
// When in verbose mode, use a following writable stream (supports
// the write function) instead of the default console
outputStream: writableStream
}
FAQs
Simple drop-in for express apps to spawn multiple processes
The npm package express-cluster receives a total of 2,647 weekly downloads. As such, express-cluster popularity was classified as popular.
We found that express-cluster demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.