Hi Guest 1 HomePage 1 Jobs 1 WalkIn 1Articles  

 :) Latest Topic
Node.js Tutorial
Parts of Node.js
Features of Node.js
Install Node.js Windows
Install Node.js Linux
Node.js First Example
Node.js Console
Node.js REPL
Node.js NPM
Node.js CL Options1
Node.js CL Option2
Node.js Globals
Node.js OS
Node.js Timer
Node.js Errors
Node.js DNS
Node.js Net
Node.js Crypto
Node.js TLS/SSL
Node.js Debugger
Node.js Process
Node.js Process Example
Node.js Process Example2
Node.js Child Process
Child Process EXEC
Child Process SPAWN
Child Process Fork
Node.js Buffers
Node.js Streams
Node.js Reading Stream
Node.js Writing Stream
Node.js Piping Stream
Node.js Chaining Streams
Node.js File System Part1
Node.js File System Part2
Node.js File System Part3
Node.js Path
Node.js StringDecoder
Node.js Query String
Node.js ZLIB
Node.js Assertion
Node.js V8
Node.js Callbacks
Node.js Events
Node.js Punycode
Node.js TTY
Node.js Web Module
Node.js Upload Files
Node.js Email Send
Node.js BuiltIn Modules
Node.js Assert Code
Node.js Assert Function
 


  

 
Node.js OS
Question Posted on 01 Feb 2024

Home >> 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.


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.



Other Important Questions
Parts of Node.js
Install Node.js Linux
Node.js First Example
Node.js Globals
Node.js DNS







 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |