Skip to content

Instantly share code, notes, and snippets.

@softwarebygabe
Last active May 27, 2018 16:09
Show Gist options
  • Save softwarebygabe/5f3f3b9adf2f2203ccf59e490ae2da29 to your computer and use it in GitHub Desktop.
Save softwarebygabe/5f3f3b9adf2f2203ccf59e490ae2da29 to your computer and use it in GitHub Desktop.
const cluster = require('cluster');
function start() {
if (cluster.isMaster) {
console.log('CLUSTER MASTER:: Starting worker process...');
cluster.fork();
// listen for disconnects and restart accordingly
cluster.on('disconnect', () => {
console.log('CLUSTER MASTER:: A worker process has disconnected. Spawning a new one...');
cluster.fork();
});
} else {
// if this is not the master process, run the worker process
require('server.js');
}
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment