Posts

Showing posts from August, 2025

Design Complete Monitor for System Uptime and Load Average

🚀 Building a CPU & Memory Monitor in Node.js node:os module imports the CPU info, memory info , uptime, system-level stats they all are coming from the os module. we design a function named monitor which calculate the CPU and Memory usage. oldCpus=os.cpus(); : This is calculating the cpus info like idle time, user time, system time etc. we call a method setTimeout() : This will call repeatly os.cpus() method for the comparison purpose . Like idle=newCpus-oldCpus const newCpus=os.cpus(); : This calculate the new cpus stats.     const usage = newCpus.map((cpu, idx) => {       return {         core: idx,         usage: calculateCPU(oldCpus[idx], newCpus[idx]) + "%",       };     }); This is calculating the usage for CPU Core where loop will execute for every core with the help of map() method and calculate the  usage percentage = calculateCPU(oldCpus[idx], newCpus[idx]) output like: ...

Pre-requisites for the Node.js

 These are the some topics which you must know before starting Node.js Variables, Functions, Objects, Arrays, Asynchronous programming (callbacks, promises, async/await), ES6+ features 1. ✅ Variables – (Storing values) Used to store data like numbers, text, etc. let name = "Avinash"; const age = 25; var city = "Patna"; let and const are preferred (ES6+). const = value doesn’t change. let = value can change. 2. 🔧 Functions – (Reusable code blocks) Used to do a task when called. function greet() { console.log("Hello!"); } greet(); // Output: Hello! You can also pass values: function add(a, b) { return a + b; } console.log(add(2, 3)); // Output: 5 3. 📦 Objects – (Group related data) Store data as key–value pairs. const person = { name: "Avinash", age: 25, city: "Patna" }; console.log(person.name); // Output: Avinash 4. 📚 Arrays – (List of values) Store multiple items in one variable. c...