Node.js OS
OS is a node module used to provide information about the computer operating system.
Advantages:
It provides functions to interact with the operating system. It provides the hostname of the operating system and returns the amount of free system memory in bytes.
Example 1:
javascript
// Include os module and create its objectvar os = require('os'); // return the cpu architectureconsole.log("CPU architecture: " + os.arch()); // It returns the amount of free system memory in bytesconsole.log("Free memory: " + os.freemem()); // It return total amount of system memory in bytesconsole.log("Total memory: " + os.totalmem()); // It returns the list of network interfacesconsole.log('List of network Interfaces: ' + os.networkInterfaces()); // It returns the operating systems default directory for temp files.console.log('OS default directory for temp files : ' + os.tmpdir ()); |
Output:

Example 2:
javascript
// Include os module and create its objectvar os = require('os'); // return the endianness of systemconsole.log("Endianness of system: " + os.endianness()); // It returns hostname of systemconsole.log("Hostname: " + os.hostname()); // It return operating system nameconsole.log("Operating system name: " + os.type()); // It returns the platform of osconsole.log('operating system platform: ' + os.platform()); // It returns the operating systems release.console.log('OS release : ' + os.release()); |
Output:




