Node.js os Module

  269 views   6 months ago NodeJS

Node.js built-in os module returns basic server operating system information.

To get started with os module, first create os.js file and import module on the top of file.

// import os module
const os = require('os');

Now you can use os module to get system information as below. os.type() method returns operating system type:

const sys = os.type(); // Linux

Below is the list of methods and properties of os module you can use and get system information.

Method Description Example
os.EOL The operating system-specific end-of-line marker. \n
os.arch() Returns the operating system CPU architecture x64
os.constants Contains commonly used operating system-specific constants for error codes, process signals, and so on. Object
os.cpus() Returns an array of objects containing information about each logical CPU core. Object[]
os.endianness() Returns a string identifying the endianness of the CPU for which the Node.js binary was compiled. LE
os.freemem() Returns the amount of free system memory in bytes as an integer. 10787278701
os.homedir() Returns the string path of the current user's home directory. /home/jitesh
os.hostname() Returns the host name of the operating system as a string. jitesh-dell-inspiron-3450
os.networkInterfaces() Returns an object containing network interfaces that have been assigned a network address. Object
os.platform() Returns a string identifying the operating system platform. linux
os.release() Returns information about the operating system's release Fatal
os.tmpdir() Returns the operating system's default directory for temporary files as a string. /tmp
os.totalmem() Returns the total amount of system memory in bytes as an integer. 20772641575
os.type() Returns the name of the operating system Linux
os.uptime() Returns the system uptime in number of seconds. 29980.42
os.userInfo() Returns information about the current user Object
os.version() Returns a string identifying the kernel version. #29~20.04.1-Ubuntu SMP Wed Aug 11 12:58:17 UTC 2021

I hope it will help you.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]