Node.js Global Objects

Node.js OS

Node.js OS gives some fundamental working framework related utility capacities. How about we see the rundown for the most part utilized capacities or methods.

Index Method Description
1. os.arch() This strategy is utilized to bring the working framework CPU architecture.
This strategy is utilized to bring a variety of articles containing data about every cpu/center introduced: model, speed (in MHz), and times (an item containing the quantity of milliseconds the cpu/center spent in: client, decent, sys, inert, and irq).
3. os.endianness() This technique restores the endianness of the cpu. Its potential qualities are 'BE' for huge endian or 'LE' for little endian.
4. os.freemem() This strategies restores the measure of free framework memory in bytes.
5. os.homedir() This strategy restores the home index of the current user.
This technique is utilized to restores the hostname of the working system.
7. os.loadavg() This strategy restores an exhibit containing the 1, 5, and 15 minute burden midpoints. The heap normal is a period part taken by framework movement, determined by the working framework and communicated as a partial number.
8. os.networkinterfaces() This technique restores a rundown of system interfaces.
9. os.platform() This strategy restores the working framework stage of the running PC i.e.'darwin', 'win32','freebsd', 'linux', 'sunos' etc.
10. os.release() This technique restores the working framework release.
11. os.tmpdir() This technique restores the working framework's default registry for transitory files.
12. os.totalmem() This strategy restores the aggregate sum of framework memory in bytes.
13. os.type() This technique restores the working framework name. For instance 'linux' on linux, 'darwin' on os x and 'windows_nt' on windows.
14. os.uptime() This technique restores the framework uptime in seconds.
15. os.userinfo([options]) This strategy restores a subset of the secret word record passage for the current compelling user.

Node.js OS Example 1

In this precedent, we are including some essential capacities. Make a record named os_example1.js having the accompanying code:

File: os_example1.js

  1. const os=require('os');  
  2. console.log("os.freemem(): \n",os.freemem());  
  3. console.log("os.homedir(): \n",os.homedir());  
  4. console.log("os.hostname(): \n",os.hostname());  
  5. console.log("os.endianness(): \n",os.endianness());  
  6. console.log("os.loadavg(): \n",os.loadavg());  
  7. console.log("os.platform(): \n",os.platform());  
  8. console.log("os.release(): \n",os.release());  
  9. console.log("os.tmpdir(): \n",os.tmpdir());  
  10. console.log("os.totalmem(): \n",os.totalmem());  
  11. console.log("os.type(): \n",os.type());  
  12. console.log("os.uptime(): \n",os.uptime());  

Open Node.js direction brief and run the accompanying code:

node os_example1.js  

Node.js OS Example 2

In this example, we are including remaining functions. Create a file named os_example2.js having the following code:

File: os_example2.js

  1. const os=require('os');  
  2. console.log("os.cpus(): \n",os.cpus());  
  3. console.log("os.arch(): \n",os.arch());  
  4. console.log("os.networkInterfaces(): \n",os.networkInterfaces());   

Open Node.js command prompt and run the following code:

  1. node os_example2.js  

welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.