OS Module

I. What is OS module?

The OS module provides information about the computer’s operating system.

To include the OS module, we use the require() method:

const os = require("os");

II. OS Properties and Methods

MethodDescription
arch()Returns the operating system CPU architecture
constantsReturns an object containing the operating system’s constants
cpus()Returns an array containing information about the computer’s CPUs
endianness()Returns the endianness of the CPU
EOLReturns the end-of-line marker for the current operating system
freemem()Returns the number of free memory of the system
hostname()Returns the hostname of the operating system
loadavg()Returns an array containing the load averages, (1, 5, and 15 minutes)
networkInterfaces()Returns the network interfaces that has a network address
platform()Returns information about the operating system’s platform
release()Returns information about the operating system’s release
tmpdir()Returns the operating system’s default directory for temporary files
totalmem()Returns the number of total memory of the system
type()Returns the name of the operating system
uptime()Returns the uptime of the operating system, in seconds
userInfo()Returns information about the current user

Learning resources:

III. Examples

// Platform
console.log(os.platform());

// CPU Arch
console.log(os.arch());

// CPU Core Info
console.log(os.cpus());

// Free memory
console.log(os.freemem());

// Total memory
console.log(os.totalmem());

// Home dir
console.log(os.homedir());

// Uptime
console.log(os.uptime());