Last active
May 27, 2018 16:09
-
-
Save softwarebygabe/5f3f3b9adf2f2203ccf59e490ae2da29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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