What does the node:os module provide, and what are some commonly used functions from it?
Short answer
os exposes OS-level info: platform() (OS name), cpus() (core details), totalmem()/freemem() (memory stats), homedir(), and tmpdir() -- useful for cross-platform scripts, sizing worker pools, and diagnostic logging.
Advertisement
AModel answer
os exposes OS-level info: platform() (OS name), cpus() (core details), totalmem()/freemem() (memory stats), homedir(), and tmpdir() -- useful for cross-platform scripts, sizing worker pools, and diagnostic logging.
console.log('Platform:', os.platform());
console.log('Free memory (GB):', (os.freemem() / 1e9).toFixed(2));Real-world example
A monitoring script logs os.freemem() and os.cpus().length to help diagnose whether periodic slowdowns stem from low memory or insufficient CPU cores.
Likely follow-ups
- How does os.tmpdir() behave differently across Windows, macOS, and Linux?
- What's the difference between os.uptime() and process.uptime()?
Related topics