![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
clusterhub
Advanced tools
An attempt at giving multi process node programs a simple and efficient way to share data.
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
var hub = require('clusterhub');
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
} else {
hub.on('event', function(data) {
// do something with `data`
});
// emit event to all workers
hub.emit('event', { foo: 'bar' });
}
Node.js is a perfect candidate to developing Date Intensive Real-time Applications. Load balancing in these applications can become complicated when having to share data between processes.
A remote database can be an easy solution for this, but it's not the most optimal. Communicating with a local process is several times faster than opening remote requests from a database. And even if the database is hosted locally, the overhead of communicating with yet another program is lessened.
clusterchat, a multi process chat applicationa that uses socket.io was made with clusterchat by allowing socket.io to sync its data using socket.io-clusterhub.
Note that this module is still experimental. It currently works by using a process's internal messaging system.
Clusterhub already comes with a default global hub. Use this if you want to create a custom hub.
Call to disable hub from emitting and receiving remote messages/commands.
Returns an array of all workers (child processes) spawned with cluster.fork()
.
Additionally, all functions from the regular EventEmitter are included. Plus a couple of extras.
Use this to emit an event only to the current process.
Use this to emit an event only to other worker processes and master. Or only to workers if the current process is the master.
hub.on('remotehello', function() {
// hello from another process
});
hub.emitRemote('remotehello', { hello: 'there' });
All functions from EventVat are included as well. Their returned value can be accessed by providing a callback as the last argument. Or directly if used by the master.
hub.set('foo', 'bar', function() {
hub.get('foo', function(val) {
console.log(val === 'bar'); // true
});
});
var returnedVal = hub.incr('foo', function(val) {
console.log(val === 1); // true
});
console.log(returnedVal === 1); // true
npm install clusterhub
Tests are written with mocha
npm test
MIT
FAQs
Easily and efficiently sync data in your cluster applications.
The npm package clusterhub receives a total of 39 weekly downloads. As such, clusterhub popularity was classified as not popular.
We found that clusterhub 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.