Skip to content

Instantly share code, notes, and snippets.

@vanquyet94
Forked from ando-takahiro/cluster-worker-id.js
Created September 27, 2022 04:30
Show Gist options
  • Save vanquyet94/91726685dd6737be6e4310e5d1b70dfc to your computer and use it in GitHub Desktop.
Save vanquyet94/91726685dd6737be6e4310e5d1b70dfc to your computer and use it in GitHub Desktop.
what is cluster.worker.id?
var cluster = require('cluster');
if (cluster.isMaster) {
for (var i = 0; i < 4; ++i) {
cluster.fork();
}
} else {
console.log(process.pid, cluster.worker.id);
}
/* output is here
$ node app.js
13747 1
13750 4
13748 2
13749 3
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment