OS

Learn about the OS module in Node.js.

We'll cover the following

All the information

The os module is a very nifty little module that allows us to get information about the OS. While it has a lot of operating system-related utility methods and properties, we will just look at a few common ones. Run the code below and see if you understand what each output means.

Press + to interact
const os = require('os');
console.log("Architecture:", os.arch(), "\n")
console.log("CPUs:", os.cpus(), "\n")
console.log("Network interfaces:", os.networkInterfaces(), "\n")
console.log("Platform:", os.platform(), "\n")
console.log("Release number:", os.release(), "\n")
console.log("User info:", os.userInfo(), "\n")

Too much information?

Don’t feel overwhelmed by everything that was printed in the output; we’ll explain everything.

Methods Explanation
os.arch() Returns the operating system CPU architecture
os.cpus() Returns an array of objects containing information about each logical CPU core
os.networkInterfaces() Returns an object containing network interfaces that have been assigned a network address
os.platform() Returns a string identifying the operating system platform
os.release() Returns a string that identifies the operating system release number
os.userInfo() Returns information about the current user

Depending on how much you have interacted with a similar module in a different language, or perhaps, the command line terminal, these commands may either seem self-explanatory or downright confusing. The purpose of this introductory course is to get you familiarized with the different modules that Node.js has to offer; you may not even use or come across some of these. The os module is rarely used, but now you know that it’s available if you need it.

Get hands-on with 1300+ tech skills courses.