🖥️ Node.js OS Module

Last Updated: 26th October 2025


  • The os module in Node.js provides operating system-related utility methods and properties.
  • You can use it to get information about the system your Node.js app is running on.

Hinglish Tip 🗣: Socho os module ek “system info tool” hai jo bata sakta hai RAM, CPU, OS type aur username jaise details programmatically.


✏ Importing OS Module

// CommonJS
const os = require("os");

// ES6 Module
import os from "os";

Common Methods & Properties

Method / PropertyPurposeExampleOutput
os.arch()CPU architectureos.arch()'x64'
os.platform()Operating system platformos.platform()'win32', 'linux', 'darwin'
os.type()OS nameos.type()'Windows_NT', 'Linux', 'Darwin'
os.uptime()System uptime in secondsos.uptime()56789
os.cpus()CPU infoos.cpus()Array of CPU cores
os.freemem()Free memory in bytesos.freemem()234567890
os.totalmem()Total system memory in bytesos.totalmem()17179869184
os.homedir()Current user home directoryos.homedir()'C:\Users\User'
os.hostname()System hostnameos.hostname()'DESKTOP-ABC123'
os.networkInterfaces()Network interfaces infoos.networkInterfaces()Object with interfaces

💡 Quick Practice

  • Print your OS platform, type, and architecture.
  • Display the total and free memory.
  • Log all network interfaces and hostname.
  • Check how long the system has been running.