Explain the Process Object in Node.js
Last Updated :
28 Apr, 2025
In this article, we are going to explore about process object of Node.js in detail. The Process object in node.js is a global object that can be used in any module without requiring it in the environment. This object is useful in the perspective of getting the information related to the node.js environment and sets of the runtime of a program.
Listed below are the events of the process:
We will describe each of the events below:
1. beforeExit Event: This event is fired when all the task of the program is done and the program is about to exit but it will always execute before the exit event.
Note: You will more clarification between exit Event and beforeExit Event in the next example.
Let's understand with the help of an implementation as explained below:
JavaScript
process.on('beforeExit', function (code) {
console.log("Executed After finishing "
+ "all the tasks with code: ", code);
});
function add(arr) {
let ans = 0
for (let ele of arr) {
ans += ele
}
return ans
}
const store = add([1, 2, 3, 4, 5]);
console.log("Addition :", store);
Output:
Addition : 15
Executed After finishing all the tasks with code: 0
2. exit Event: This event is fired or executed when the program has finished all the tasks and is just about to exit from the program but it always gets fired after the beforeExit Event.
Let's understand with the help of an implementation as explained below:
JavaScript
process.on('exit', function (code) {
console.log("Executed After the "
+ "beforeExit Event: ", code);
});
process.on('beforeExit', function (code) {
console.log("Executed After finishing "
+ "all the tasks with code: ", code);
});
function add(arr) {
let ans = 0
for (let ele of arr) {
ans += ele
}
return ans
}
const store = add([1, 2, 3, 4, 5]);
console.log("Addition :", store);
Output:
Addition : 15
Executed After finishing all the tasks with code: 0
Executed After the beforeExit Event: 0
Explanation: As you see that the exit event has been executed after the beforeExit Event. So, now you would have got a clear difference between the exit Event and beforeExit Event.
3. config Event: This event gives the object of the current node.js executable file and gives brief information about the currently running file.
Let's understand with the help of an implementation as explained below:
JavaScript
function add(arr) {
let ans = 0
for (let ele of arr) {
ans += ele
}
return ans
}
const store = add([1, 2, 3, 4, 5]);
console.log("Addition :", store);
console.log(process.config);
Output:
4. argv Event: The process.argv property gives an array containing the command-line arguments passed. The first argument always gives the executable path and the second argument will give us the path of the executable javascript file and the remaining will be an additional argument for the command line argument.
Let's understand with the help of an implementation as explained below:
JavaScript
process.argv.forEach((val, index) => {
console.log(index + ":" + val);
});
Output:
Similar Reads
Node.js process Object A process object is a global object, so it can be accessed from anywhere. As it is a predefined library, so we don't have to download it to our system globally. Prerequisites: Basic knowledge of  NodeNode.js installed (version 12+)NPM installed (version 6+)Requiring Module: You can include the modul
2 min read
What is the purpose of process object in Node.js ? 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
2 min read
Node.js process.report Object The process.report is an object found under the Process Module of Node.js. process.report have many methods such as 'writeReport', 'getReport', 'directory', 'filename', 'compact', 'signal', 'reportOnFatalError', 'reportOnSignal', and 'reportOnUncaughtException'. These methods are used to generate di
3 min read
What is the purpose of the process object in Node JS ? In NodeJS, the process object is a global object that provides access to information and control over the current NodeJS process. It offers various properties and methods to interact with the underlying operating system environment and manage the NodeJS process effectively. Let's explore the primary
2 min read
Explain the Concept of Child Processes in Node Child processes in Node provide a way to execute multiple processes simultaneously, enabling efficient handling of tasks that can benefit from parallel execution. This concept is particularly useful for tasks such as running CPU-intensive computations, performing I/O operations, or executing externa
2 min read