Q1. What is the OS module in Node.js?
The OS module provides operating system-related utility methods and properties. It's a core module, included with:
const os = require('os'). It gives information about the system like CPU architecture, memory, network interfaces, and system uptime. Useful for system monitoring and optimization.Q2. What information can you get about the CPU using OS module?
os.cpus() returns an array of objects with information about each CPU/core: model, speed (in MHz), and times (user, nice, sys, idle, irq). os.arch() returns the CPU architecture (e.g., 'x64', 'arm'). os.loadavg() returns an array of load averages (1, 5, 15 minutes) on Unix-like systems.
Q3. How do you get memory information with OS module?
os.totalmem() returns the total system memory in bytes. os.freemem() returns the free memory in bytes. You can convert to megabytes:
(os.freemem() / 1024 / 1024).toFixed(2) + ' MB'. This is useful for monitoring application memory usage and system health.Q4. What network information can you get?
os.networkInterfaces() returns an object with network interface details. It lists all network interfaces (like 'eth0', 'wlan0') with their addresses (IPv4, IPv6), MAC address, netmask, and whether it's internal. Useful for finding server IP addresses dynamically.
Q5. What other useful methods does OS module provide?
os.hostname() returns the system hostname. os.platform() returns 'darwin', 'win32', 'linux', etc. os.release() returns the operating system release. os.type() returns the OS name. os.uptime() returns system uptime in seconds. os.userInfo() returns information about the current user.
