How to put cpuUsage value in variable through os-utils provided by node js

Viewed 28
var os  = require('os-utils');
os.cpuUsage(function(v){
    v = Math.round(v*100);
    console.log( `os-utils get CPU Usage : ${v}%`);
    return v
});
var cpuUsage = os.cpuUsage(v()); 
console.log('what is that '+ cpuUsage); console.log(v); // undefined

I want to put the value in a variable and declare it as a global variable. I can't understand the asynchronous way. Please help me how to set up the callback function

0 Answers
Related