Open In App

What is the purpose of process object in Node.js ?

Last Updated : 14 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

A process object is a global object available in the Node.js environment. It is globally available. We do not have to use the require() to import the module of the process object. The “process” object use to get current Node.js process details & also give control over that process.

Properties of the process object: Some of the commonly used Node.js process properties are given below.

1. process.version: It returns the Node.js version installed on your machine. This is an alternative to node -v or node –version.

Example:

Javascript




const process = require('process');
console.log(process.version);


Output:

 

2. process.versions: It returns the details about the Node.js version in a very descriptive way & its dependencies installed on your machine. 

Example:

Javascript




const process = require('process');
console.log(process.versions);


Output:

 

3. process.argv: It returns the argument passed in the command line. This returns an array where the first element is Node, the second is file path & from the third element onwards contains the arguments you actually passed.

Example:

Javascript




const process = require('process');
const array = process.argv;
console.log(array);


Output:

 

4. process.env: It returns the user environment details & its variables. For example, if the system has a SECRET variable set, then it can be accessed through process.env.SECRET.

Example:

Javascript




const process = require('process');
console.log(process.env);


Output:

 

5. process.release: It returns the metadata for the current node version. It will contain properties like name, sourceUrl, headersUrl, libUrl, etc. 

Example:

Javascript




const process = require('process');
console.log(process.release);


Output:

 

6. process.platform: It returns the operating system platform of the process. Such as ‘win32’, if you are using windows, or ‘aix’, ‘android’, ‘darwin’, ‘freebsd’, ‘linux’, ‘openbsd’, ‘sunprocess’ for other operating systems.

Example:

Javascript




const process = require('process');
console.log(process.platform);


Output:

 

7. process.arch: It returns the CPU architecture of the computer for which the current node.js is compiled. Such as  â€˜x32’, ‘x64’, ‘arm’, ‘arm64’, ‘s390’, ‘s390x’, ‘mipsel’, ‘ia32’, ‘mips’, ‘ppc’ and ‘ppc64’.

Example:

Javascript




const process = require('process');
console.log(process.arch);


Output:

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads