node js - Node js Process - node - node js tutorial - webnode




What is Node.js Process?

  • The process object is a global that provides information about, and control over, the current Node.js process.
  • Node.js provides the facility to get process information such as process id, architecture, platform, version, release, uptime, upu usage etc.
  • It can also be used to kill process, set uid, set groups, unmask etc.
  • The process is a global object, an instance of EventEmitter, can be accessed from anywhere.
 nodejs-process-model

Learn Node js - node js Tutorial - nodejs process model - node - Node js Examples

Node.js Process Properties

  • A list of commonly used Node.js process properties are given below.
PropertyDescription
archreturns process architecture: 'arm', 'ia32', or 'x64'
argsreturns commands line arguments as an array
envreturns user environment
pidreturns process id of the process
platformreturns platform of the process: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
releasereturns the metadata for the current node release
versionreturns the node version and its dependencies

Node.js Process Properties Example

  • Let's see the simple process example to print architecture, pid, platform and version of the process.
  • Node JS Tutorial File: process_example1.js

process_example1.js

console.log(`Process Architecture: ${process.arch}`);  
console.log(`Process PID: ${process.pid}`);  
console.log(`Process Platform: ${process.platform}`);  
console.log(`Process Version: ${process.version}`);  
  • Open Node.js command prompt and run the following code:

node process_example1.js

 nodejs-process-example1

Learn Node js - node js Tutorial - nodejs-process-example1 - node - Node js Examples

  • Let's see another process example to print command line arguments.
  • Here node is considered as the first argument, filename is considered as the second argument and actual command line arguments are considered as third, fourth, fifth and so on.
  • Node JS Tutorial File: process_example2.js

process_example2.js

process.argv.forEach((value, index, array) => {  
  console.log(`${index}: ${value}`);  
});  
  • Open Node.js command prompt and run the following code:

node process_example2.js

 nodejs-process-example2

Learn Node js - node js Tutorial - nodejs-process-example2 - node - Node js Examples

  • A list of commonly used Node.js process functions are given below.
FunctionDescription
cwd()returns path of current working directory
hrtime()returns the current high-resolution real time in a [seconds, nanoseconds] array
memoryUsage()returns an object having information of memory usage.
process.kill(pid[, signal])is used to kill the given pid.
uptime()returns the Node.js process uptime in seconds.

Node.js Process Functions Example

  • Let's see the process example to print current working directory and uptime of the process.
  • Node JS Tutorial File: process_example3.js

process_example3.js

console.log(`Current directory: ${process.cwd()}`);  
console.log(`Uptime: ${process.uptime()}`);  
  • Open Node.js command prompt and run the following code:

node process_example3.js

 nodejs-process-example3

Learn Node js - node js Tutorial - nodejs-process-example3 - node - Node js Examples


This wikitechy technological portal provides you whole lot of information related to the topics such as mongodb tutorial , what is node js , express js tutorial , node js tutorial pdf , learn node js , node js tutorial for beginners , node js tutorial w3schools , node js express , javascript for beginners , node js express tutorial , node js tutorial point , node js book , node js server , note js , node js mongodb , what is node js used for , why node js , node tutorial , node js basics , tutorialspoint node js , node express , node js sample application , nodeschool , node js for beginners , express tutorial , node js application , use of node js , npm tutorial , node js org , node js training , node js online training , node js tutorial beginner , how to use node js , node js hello world , express node js , node js mongodb tutorial , nodejs http , why use node js

Related Searches to Node.js Process

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×