Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
clusterfork
Advanced tools
An extremely simple way to cluster your node process for production purposes
An extremely simple way to cluster your node process for production purposes
npm install clusterfork --save
If you have an application called your-app
and a service runs automatically when it is required, then you only need this in your index.js file.
var cf = require('clusterfork'),
app = require('your-app'),
production = process.env.production || false;
cf(app, production ? 0 : 1, false);
The first argument of ClusterFork is the function where it will spin up your server. Then can be a more complex object, like app.run
, but it needs to be the forking function of your server.
It can also be a path to a file that needs to be required cf('./app.js', 1)
and you can specify if there's a particular function under that required file that needs to be ran instead by using an array instead cf(['./app.js', 'run'], 1)
.
The second argument is the amount of workers needed to be spun up. By default, this defaults to 1 for development purposes. If 0 is specified, ClusterFork will try to create as many forks as there are CPUs available to it. If the number of requested workers exceed the number of CPUs, it will simply used the maximum CPU amount.
The third argument to is let ClusterFork know to restart a forked process that has died. By default, this is false. This is sometimes useful in production when your app dies violently, but still want it to restart and keep up with the load, but it might keep dying again if it hit the same edge case.
ClusterFork can also be used within a command line. This is useful if you don't want a direct dependency to ClusterFork within your codebase, or that the codebase isn't "yours".
clusterfork -w 4 ./app.js run
There are only two options available, -w
or --worker
which is the amount of workers or -p
or --production
which does the same as -w 0
which is to say, use the maximum amount of CPUs available.
Then you simply need to specify the file to require, and optionaly, which function to call within said file.
FAQs
An extremely simple way to cluster your node process for production purposes
We found that clusterfork 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.