🖥️ Node.js OS Module
Last Updated: 26th October 2025
- The
osmodule 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
osmodule 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 / Property | Purpose | Example | Output |
|---|---|---|---|
| os.arch() | CPU architecture | os.arch() | 'x64' |
| os.platform() | Operating system platform | os.platform() | 'win32', 'linux', 'darwin' |
| os.type() | OS name | os.type() | 'Windows_NT', 'Linux', 'Darwin' |
| os.uptime() | System uptime in seconds | os.uptime() | 56789 |
| os.cpus() | CPU info | os.cpus() | Array of CPU cores |
| os.freemem() | Free memory in bytes | os.freemem() | 234567890 |
| os.totalmem() | Total system memory in bytes | os.totalmem() | 17179869184 |
| os.homedir() | Current user home directory | os.homedir() | 'C:\Users\User' |
| os.hostname() | System hostname | os.hostname() | 'DESKTOP-ABC123' |
| os.networkInterfaces() | Network interfaces info | os.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.