Skip to content

Instantly share code, notes, and snippets.

View SalvatoreAD's full-sized avatar

SalvatoreAD SalvatoreAD

  • Avellino
  • 05:12 (UTC -12:00)
View GitHub Profile
@bag-man
bag-man / cpu.js
Last active March 29, 2024 12:01
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores