Node.js Operating SYstem will provides basic OS related utility functions. And to understand this we will take 2 example tom understand some methods and syntax.
Node.js OS Example 1
Well in below example, we are adding some basi functions. And we create a file which name is OSExample1.js and below is the code and example fo that:-
File: OSExample1.js
const os=require('os');
console.log("os.freemem(): \n",os.freemem());
console.log("os.homedir(): \n",os.homedir());
console.log("os.hostname(): \n",os.hostname());
console.log("os.endianness(): \n",os.endianness());
console.log("os.loadavg(): \n",os.loadavg());
console.log("os.platform(): \n",os.platform());
console.log("os.release(): \n",os.release());
console.log("os.tmpdir(): \n",os.tmpdir());
console.log("os.totalmem(): \n",os.totalmem());
console.log("os.type(): \n",os.type());
console.log("os.uptime(): \n",os.uptime());
Now open Node.js command prompt and run the above code and you will get out like below:-
node OSExample1.js
Node.js OS Example 2
In this example we will include other remaining functions. You will create file name OSExample2.js, and below is the code as give below:-
File: OSExample2.js
const os=require('os');
console.log("os.cpus(): \n",os.cpus());
console.log("os.arch(): \n",os.arch());
console.log("os.networkInterfaces(): \n",os.networkInterfaces());
Now open Node.js command prompt and run the above code and you will get out like below:-
node OSExample2.js
List of OS utility functions
Let's see the list generally used functions or methods.