A modern Node.js 'cluster' example
An example of running cluster on Node 14, including w/ ESM & semantic updates for ES2020
1 | import cluster from 'cluster'; |
Changes from the current Node.js ‘cluster’ docs include:
- Using
import
overrequire
- Using named imports over the default where feasible
- Using clearer, more semantic identifier names, e.g.
currentCPU
v.i
- Replacing archaic terminology, e.g.
Master
w/Main
Output w/ ESM Node code w/ syntactical & semantic updates1
2
3
4
5
6
7
8
9
10
11
12
13
14> $ node index.mjs ⬡ 14.15.1 [±main ●]
Main 57290 is running
Worker 57292 started
Worker 57295 started
Worker 57291 started
Worker 57294 started
Worker 57293 started
Worker 57296 started
Worker 57298 started
Worker 57297 started
Worker 57299 started
Worker 57300 started
Worker 57302 started
Worker 57301 started
See here for the full repo