Node.js Process

Node.js gives the office to get process data, for example, process id, design, stage, form, discharge, uptime, upu utilization and so forth. It can likewise be utilized to slaughter process, set uid, set gatherings, expose etc.

The process is a worldwide article, an occurrence of EventEmitter, can be gotten to from anywhere.

Node.js Process Properties

A rundown of normally utilized Node.js process properties are given below.

archreturns process engineering: 'arm', 'ia32', or 'x64'
argsreturns directions line contentions as an array
envreturns client environment
pidreturns process id of the process
platformreturns stage of the procedure: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
releasereturns the metadata for the present hub release
versionreturns the hub version
versionsreturns the hub form and its dependencies

Node.js Process Properties Example

How about we see the simple procedure example to print design, pid, stage and version of the process.

File: process_example1.js

  1. console.log('Process Architecture: ${process.arch}');  
  2. console.log('Process PID: ${process.pid}');  
  3. console.log('Process Platform: ${process.platform}');  
  4. console.log('Process Version: ${process.version}');  

Open Node.js order print and run the accompanying code:

  1. node process_example1.js  

Let's see another procedure example to print direction line arguments. Here hub is considered as the principal contention, filename is considered as the second contention and genuine direction line contentions are considered as third, fourth, fifth thus on.

File: process_example2.js

  1. process.argv.forEach((value, index, array) => {  
  2.   console.log('${index}: ${value}');  
  3. });  

Open Node.js order print and run the accompanying code:

  1. node process_example2.js  

Node.js Process Functions

A rundown of normally utilized Node.js process capacities are given below.

cwd()returns way of current working directory
hrtime()returns the present high-goals constant in a [seconds, nanoseconds] array
memoryUsage()returns an article having data of memory usage.
process.kill(pid[, signal])is used to execute the given pid.
uptime()returns the Node.js procedure uptime in seconds.

Node.js Process Functions Example

Let's see the procedure example to print current working registry and uptime of the process.

File: process_example3.js

  1. console.log('Current directory: ${process.cwd()}');  
  2. console.log('Uptime: ${process.uptime()}');  

Open Node.js order print and run the accompanying code:

  1. node process_example3.js  

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