OS in Node.JS

Learn OS details with the OS module

The os module is a handy module that allows us to get details about the OS. It has a lot of operating system-related utility methods and properties. Run the code below to see details about the operating system.

const os = require('os');

console.log(`Operating System Architecture: ${os.arch()}`);
console.log(`OS Endianness: ${os.endianness()}`);
console.log(`Free System Memory: ${os.freemem()}`);
console.log(`Total System Memory: ${os.totalmem()}`);
console.log(`Platform Details: ${os.platform()}`);
console.log(`Home Directory: ${os.homedir()}`);
console.log(`OS Release: ${os.release()}`);
console.log(`OS Version: ${os.version()}`);
console.log(`OS Type: ${os.type()}`);
console.log(`Hostname: ${os.hostname()}`);
console.log(`Load Averages: ${os.loadavg()}`);
console.log(`OS Temporary Directory: ${os.tmpdir()}`);
console.log(`OS uptime: ${os.uptime()}`);

As you can see, a lot of details can be obtained from the OS module. The OS module is not used very often.

OS MethodExplanation
os.arch()Returns the OS CPU architecture for which the Node.JS binary was compiled.
os.endianness()Returns the endianness of the CPU for which the Node.JS binary was compiled.
os.freemem()Returns the amount of free system memory in bytes.
os.totalmem()Returns the total amount of system memory in bytes.
os.platform()Returns details identifying the OS platform for the Node.JS binary (set at compile time).
os.homedir()Returns the host name of the OS.
os.release()Returns the operating system.
os.version()Returns the kernel version.
os.type()Returns the OS name (e.g. 'Linux','Darwin','Windows_NT').
os.hostname()Returns the path of the current user's home directory.
os.loadavg()Returns the 1, 5, and 15 minute load averages (a measure of system activity calculated by the OS expressed as a fractional number).
os.tmpdir()Returns the OS's default directory for temporary files.
os.uptime()Returns the system uptime in number of seconds.

Reference:

Node.JS OS Module