Skip to content

Instantly share code, notes, and snippets.

@micheleriva
Last active November 10, 2018 17:23
Show Gist options
  • Save micheleriva/bdf7ba3e8a3fb109794ed2738077c5b9 to your computer and use it in GitHub Desktop.
Save micheleriva/bdf7ba3e8a3fb109794ed2738077c5b9 to your computer and use it in GitHub Desktop.
const cluster = require('cluster')
const { cpus } = require('os')
const numWorkers = cpus().length
const isMaster = cluster.isMaster
if (isMaster) {
process.stdout.write('I am master!')
const workers = [...Array(numWorkers)].map(_ => cluster.fork())
} else {
process.stdout.write('I am a worker!')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment