What is the os module in Nodejs?

The os module is a built-in Nodejs module that is used to get information about a computer’s operating system. In other words, the os module provides operating system-related utility methods and properties.

Syntax

const os = require('os');

Now, let’s take a look at some properties and methods of the os module.

os.type()

os.type() method returns the name of the operating system of the computer.

const os = require("os");
console.log(os.type())

os.arch()

This method is used to get the architecture of the operating system CPU through which the Nodejs on your machine was compiled.

const os = require('os')
console.log(os.arch())

os.hostname()

This method returns the hostname of the operating system of the computer.

const os = require('os')
console.log(os.hostname())

os.freemem()

This method gets the size of memory left in the hard disk of the operating system in bytes.

const os = require('os')
console.log(os.freemem())

os.constants

This is a property of the os module that returns the operating system’s constants for process signals, error codes, etc.

NOTE: Different machines will bring different results of the os.contants

const os = require("os");
console.log(os.constants);

That will be all for now. However, there are other methods and properties of the os module.

Thanks for your time!

Free Resources