Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created August 28, 2019 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tsh-code/84cc0ccdd4261aaa5b041ef92e49699d to your computer and use it in GitHub Desktop.
Save tsh-code/84cc0ccdd4261aaa5b041ef92e49699d to your computer and use it in GitHub Desktop.
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`)
for (let i = 0; i < numCPUs; i++) {
cluster.fork()
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`)
})
} else {
const express = require('express')
const app = express()
// define our endpoints here
app.listen(port)
console.log(`Process ${process.pid} started`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment