Node.js - Get number of processors available
Solution 1:
It's built into node and called os.cpus()
Returns an array of objects containing information about each CPU/core installed: model, speed (in MHz), and times (an object containing the number of milliseconds the CPU/core spent in: user, nice, sys, idle, and irq).
The length of this array is the number of "processors" in the system. Most systems only have one CPU, so that's the number of cores of that CPU.
See the code below:
const os = require('os')
const cpuCount = os.cpus().length
Solution 2:
var os = require('os'),
cpuCount = os.cpus().length;