Run your application as cluster mode in middleware! ๐
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install grupo
import grupo from "grupo";
Grupo has options as parameter and has own logger in it. You can enable and disable it as you wish by using options. Run your application in cluster mode and choose how many thread you need.
Grupo accepts these properties in the options object.
interface options {
instance?: number;
log?: boolean;
}
Instance is counter for how many thread you wan't to use, of course is limit how much you have.
// Will use 3 thread
// The default value is 0, so will use all cores
app.use(
grupo({
instance: 3,
})
);
Log is an boolean that turn off and on logs about your cluster.
// Will print logs about cluster
// The default value is true
app.use(
grupo({
log: false,
})
);
var express = require("express");
var grupo = require("grupo");
var app = express();
app.use(grupo(3000));
app.get("/", function (req, res) {
res.send("hello, world!");
});
app.listen(3000)
var finalhandler = require("finalhandler");
var http = require("http");
var grupo = require("grupo");
// create "middleware"
var logger = grupo(3000);
http.createServer(function (req, res) {
var done = finalhandler(req, res);
logger(req, res, function (err) {
if (err) return done(err);
// respond to request
res.setHeader("content-type", "text/plain");
res.end("hello, world!");
});
});