I tried this as my first code and i am getting error
const cluster = require('cluster');
const http = require('http');
const numCPUs = 4;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('online', function(worker) {
console.log('Worker ' + worker.process.pid + ' is online');
});
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
// Workers can share any TCP connection
// In this case it is an HTTP server
http.createServer((req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(8000);
}
This is the Error i am getting :-
Worker 11056 is online Worker 11057 is online Worker 11058 is online Worker 11059 is online events.js:141 throw er; // Unhandled 'error' event ^
Error: bind EADDRINUSE null:8000 at Object.exports._errnoException (util.js:870:11) at exports._exceptionWithHostPort (util.js:893:20) at cb (net.js:1302:16) at rr (cluster.js:594:14) at Worker. (cluster.js:564:9) at process. (cluster.js:714:8) at emitTwo (events.js:92:20) at process.emit (events.js:172:7) at handleMessage (internal/child_process.js:689:10) at Pipe.channel.onread (internal/child_process.js:440:11) events.js:141 throw er; // Unhandled 'error' event ^
Error: bind EADDRINUSE null:8000 at Object.exports._errnoException (util.js:870:11) at exports._exceptionWithHostPort (util.js:893:20) at cb (net.js:1302:16) at rr (cluster.js:594:14) at Worker. (cluster.js:564:9) at process. (cluster.js:714:8) at emitTwo (events.js:92:20) at process.emit (events.js:172:7) at handleMessage (internal/child_process.js:689:10) at Pipe.channel.onread (internal/child_process.js:440:11) events.js:141 throw er; // Unhandled 'error' event ^
Error: bind EADDRINUSE null:8000 at Object.exports._errnoException (util.js:870:11) at exports._exceptionWithHostPort (util.js:893:20) at cb (net.js:1302:16) at rr (cluster.js:594:14) at Worker. (cluster.js:564:9) at process. (cluster.js:714:8) at emitTwo (events.js:92:20) at process.emit (events.js:172:7) at handleMessage (internal/child_process.js:689:10) at Pipe.channel.onread (internal/child_process.js:440:11) worker 11056 died worker 11057 died worker 11058 died events.js:141 throw er; // Unhandled 'error' event ^
Error: bind EADDRINUSE null:8000 at Object.exports._errnoException (util.js:870:11) at exports._exceptionWithHostPort (util.js:893:20) at cb (net.js:1302:16) at rr (cluster.js:594:14) at Worker. (cluster.js:564:9) at process. (cluster.js:714:8) at emitTwo (events.js:92:20) at process.emit (events.js:172:7) at handleMessage (internal/child_process.js:689:10) at Pipe.channel.onread (internal/child_process.js:440:11) worker 11059 died