Skip to main content
Node.js Code Completion Hard +35 XP

Cluster Fork

Complete to spawn a worker process per CPU.

Node.jsFill in the blank
const cluster = require('cluster');
if (cluster.isPrimary) {
  os.cpus().forEach(() => cluster.___());
}

Type the missing code

Show answer and explanation

Answer: fork

cluster.fork() spawns a new worker process. Using one per CPU core maximizes multi-core utilization in Node.js.

Hint: Which method creates a new worker process?

What this challenge tests

Code Completion in Node.js: cluster, performance.

Related challenges