Node.js OS Module

Node.js OS Module

The OS module in Node.js provides information about the computer’s operating system.
It is a built-in module, so no installation is required.


Import OS Module



📌 Common OS Module Methods


1️⃣ os.platform()

Returns the Operating System platform.


Output example:

win32

2️⃣ os.type()

Returns the OS name.


Output example:

Windows_NT

3️⃣ os.release()

Returns OS version.



4️⃣ os.arch()

Returns CPU architecture.


Output:

x64

5️⃣ os.cpus()

Returns CPU information.



6️⃣ os.totalmem()

Returns total system memory (in bytes).



7️⃣ os.freemem()

Returns free memory (in bytes).



8️⃣ os.hostname()

Returns computer name.



9️⃣ os.homedir()

Returns user’s home directory.



🔟 os.uptime()

Returns the system uptime in seconds.



1️⃣1️⃣ os.networkInterfaces()

Returns network details like IP address.



📄 Complete Example


 


🎯 Where OS Module Is Used

✔ System monitoring
✔ Checking CPU or memory usage
✔ Building CLI tools
✔ Creating system utilities
✔ Logging device information

You may also like...