Node.js Process beforeExit Event Last Updated : 25 May, 2021 Comments Improve Suggest changes Like Article Like Report The 'beforeExit' is an event of class Process within the process module which is emitted when Node.js empties its event loop and has no additional work to schedule. Syntax: Event: 'beforeExit'Parameters: This event does not accept any argument as the parameter. Return Value: This event returns nothing but a callback function for further operation. Example 1: index.js // Node.js program to demonstrate the // Process 'beforeExit' Event // Importing process module const process = require('process'); // Event 'beforeExit' process.on('beforeExit', (code) => { console.log('Process beforeExit event with code: ', code); }); // Event 'exit' process.on('exit', (code) => { console.log('Process exit event with code: ', code); }); // Display the first message console.log('This message is displayed first.'); Run the index.js file using the following command: node index.jsOutput: This message is displayed first. Process beforeExit event with code: 0 Process exit event with code: 0Example 2: index.js // Node.js program to demonstrate the // Process 'beforeExit' Event // Importing process module const process = require('process'); // Updating the exit code process.exitCode = 100; // Event 'beforeExit' process.on('beforeExit', (code) => { console.log('Process beforeExit event with code: ', code); }); // Display the first message console.log('This message is displayed first.'); Run the index.js file using the following command: node index.jsOutput: This message is displayed first. Process beforeExit event with code: 100Reference: https://nodejs.org/dist/latest-v16.x/docs/api/process.html#process_event_beforeexit Comment More infoAdvertise with us Next Article Node.js Process beforeExit Event R rohitprasad3 Follow Improve Article Tags : Web Technologies Node.js Node.js-process-module Similar Reads Node.js Process disconnect Event In this article, we will discuss about the disconnect event of the Process object. The disconnect event will be issued when the IPC channel is closed if the Node.js process was started using an IPC channel. Syntax: process.on('disconnect', () => { // Disconnect event }); The below examples illust 1 min read Node.js Process exit Event The process is the global object in Node.js that keeps track of and contains all the information of the particular node.js process that is executing at a particular time on the machine. The process.exit() method is the method that is used to end the Node.js process. Every process action on the mach 2 min read How to Exit Process in Node.js ? In this article, we will see how to exit in NodeJS application. There are different types of methods to exit in Nodejs application, here we have discussed the following four methods. Table of Content Using ctrl+C keyUsing process.exit() FunctionUsing process.exitCode variableUsing process.on() Funct 3 min read Node.js Process Signal Events Signals are a POSIX (The Portable Operating System Interface) intercommunication system. These events will be emitted when Node receives signal events. In order to notify that an event has occurred, a notification is sent. The signal handler will receive the signal's name and the signal name is uppe 3 min read Node.js Process message Event The 'message' is an event of class Process within the process module which is emitted whenever a message sent by a parent process using childprocess.send() is received by the child process. Syntax: Event: 'message'Parameters: This event does not accept any argument as a parameter. Return Value: This 2 min read Like