What is the os module in Node.js?

Why Interviewers Ask This

This is a classic screening question for Node.js roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

The os module provides operating system-related utility methods and properties. Key features: os.platform() — returns the OS platform: "linux", "darwin" (macOS), "win32"; os.arch() — CPU architecture: "x64", "arm64"; os.cpus() — array of CPU core info (model, speed, times); os.freemem() / os.totalmem() — free and total system memory in bytes; os.hostname() — machine hostname; os.userInfo() — current user info (username, homedir); os.homedir() — home directory path; os.tmpdir() — default temp directory path; os.networkInterfaces() — network interfaces with IP addresses; os.uptime() — system uptime in seconds; os.EOL — OS-specific line ending (\r\n on Windows, \n on Unix). Useful for writing cross-platform CLI tools and system monitoring utilities.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.