crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

Node.js OS
Question Posted on 01 Feb 2024Home >> Tutorial >> Node.js Tutorial >> Node.js OS

Node.js OS

Node.js Operating System



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




OS Nodejs


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




OS Other NodeJS


List of OS utility functions



Let's see the list generally used functions or methods.
0
0

IndexMethodDescription
1os.arch()This method is used to fetch the operating system CPU architecture.
2os.cpus()This method is used to fetch an array of objects containing information about each cpu/core installed: model, speed (in MHz), and times (an object containing the number of milliseconds the cpu/core spent in: user, nice, sys, idle, and irq).
3os.endianness()This method returns the endianness of the cpu. Its possible values are 'BE' for big endian or 'LE' for little endian.
4os.freemem()This methods returns the amount of free system memory in bytes.
5os.homedir()This method returns the home directory of the current user.
6os.hostname()This method is used to returns the hostname of the operating system.
7os.loadavg()This method returns an array containing the 1, 5, and 15 minute load averages. The load average is a time fraction taken by system activity, calculated by the operating system and expressed as a fractional number.
8os.networkinterfaces()This method returns a list of network interfaces.
9os.platform()This method returns the operating system platform of the running computer i.e.'darwin', 'win32','freebsd', 'linux', 'sunos' etc.
10os.release()This method returns the operating system release.
11os.tmpdir()This method returns the operating system's default directory for temporary files.
12os.totalmem()This method returns the total amount of system memory in bytes.
13os.type()This method returns the operating system name. For example 'linux' on linux, 'darwin' on os x and 'windows_nt' on windows.
14os.uptime()This method returns the system uptime in seconds.
15 os.userinfo([options]) This method returns a subset of the password file entry for the current effective user.


.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

Parts of Node.js

Install Node.js Linux

Node.js First Example

Node.js Globals

Node.js DNS






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap