◐ Shell
clean mode source ↗

doc: move numCPUs require to top of file in cluster CJS example · nodejs/node@30310bf

Original file line numberDiff line numberDiff line change

@@ -317,6 +317,7 @@ if (cluster.isPrimary) {

317317

```cjs

318318

const cluster = require('node:cluster');

319319

const http = require('node:http');

320+

const numCPUs = require('node:os').availableParallelism();

320321

const process = require('node:process');

321322
322323

if (cluster.isPrimary) {

@@ -335,7 +336,6 @@ if (cluster.isPrimary) {

335336

}

336337
337338

// Start workers and listen for messages containing notifyRequest

338-

const numCPUs = require('node:os').availableParallelism();

339339

for (let i = 0; i < numCPUs; i++) {

340340

cluster.fork();

341341

}