When I needed to get memory, cpu and disk information on NodeJS, I ended up looking for answers on stackoverflow and using multiple packages with some code. I am putting all together here.
npm install @felipebutcher/node-os-infoThe values that this package show are the same as in htop, which were what I was looking for.
bash
npm install @felipebutcher/node-os-info
`Usage
All the three variables (memory, cpu and disk) are a number between 0 and 1, representing the percentage of use of each resource.`node
const osInfo = require("@felipebutcher/node-os-info");osInfo.mem(memory => {
console.log("Memory: " + Math.round(memory * 100) + "%");
});
osInfo.cpu(cpu => {
console.log("CPU: " + Math.round(cpu * 100) + "%");
});
osInfo.disk(disk => {
console.log("Disk: " + Math.round(disk * 100) + "%");
});
``