express-clusterize
v1.1.0
Published
A no-nonsense clustering solution for your apps.
Downloads
15
Readme
express-clusterize
A no-nonsense clustering solution for your nodeJS apps. Designed for a painless out of the box experience.
Installation
With npm
:
$ npm install --save express-clusterize
With yarn
:
$ yarn add express-clusterize
Usage
clusterize(entrypoint[,options])
For most applications it's as simple as wrapping your app.listen
call in a function and passing it to clusterize
. Let's take a look at an example.
Before
const express = require('express');
const app = express();
const port = 3000;
app.listen(port, () => {
console.log(`Application started on port ${port}!`);
});
After
const express = require('express');
const clusterize = require('express-clusterize');
const app = express();
const port = 3000;
clusterize(() => {
app.listen(port, () => {
console.log(`Application started on port ${port}!`);
});
});
That's it! There are three configuration options you can pass in the second argument to customize your experience:
children
Controls the number of worker processes spawned. Defaults to require('os').cpus().length
.
prodOnly
If set, we only fork worker processes when NODE_ENV === 'production'
. Defaults to false
.
respawn
If set, respawns child processes if they die. Defaults to true
.