I have an express.js application and it should start the subprocess every time there is a specific request (here it is: / compute / real-time). To calculate the data, user scripts will be created. So, I use the cluster node module to create a working pool and choose the one that can run scripts freely. But I hit the wall while creating the cluster itself. Here is the clusterPool.js code
var cluster = require('cluster');
exports.setupCluster = function(){
console.log ("Setting up cluster for bot processing " )
if (cluster.isMaster){
cluster.fork();
}
}
compute.js
var async = require('async');
var clusterPool = require('.././clusterPool')
clusterPool.setupCluster();
exports.computeRealTime = function(req,res){
clusterPool.cluster.on("listening",function(worker){
})
}
webserver.js
var express = require('express');
var compute = require('.././compute');
var app = express();
app.get('/compute/real-time',compute.computeRealTime);
app.listen(3000);
Here is the error I am facing:
error: code=EADDRINUSE, errno=EADDRINUSE, syscall=bind
error: Error: bind EADDRINUSE
at errnoException (net.js:884:11)
at net.js:1056:26
at Object.1:2 (cluster.js:587:5)
at handleResponse (cluster.js:171:41)
at respond (cluster.js:192:5)
at handleMessage (cluster.js:202:5)
at process.EventEmitter.emit (events.js:117:20)
at handleMessage (child_process.js:318:10)
at child_process.js:392:7
at process.handleConversion.net.Native.got (child_process.js:91:7)
Is there any way out for this problem please? thanks in advance
source
share