Node.js Process message Event Last Updated : 07 Aug, 2021 Comments Improve Suggest changes Like Article Like Report 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 event returns nothing but a callback function for further operation. Example 1: The filename is index.js JavaScript // Node.js program to demonstrate the // Process 'message' Event // Importing process module const cp = require('child_process'); // Initiating child process const process = cp.fork(`${__dirname}/sub.js`); // Causes the child to print: // CHILD got message: { hello: 'world' } process.send({ hello: 'world' }); Here the file name is sub.js JavaScript // Importing process module const process = require('process'); // Message Event process.on('message', (m) => { console.log('CHILD got message:', m); process.exit(0) }); Run the index.js file using the following command: node index.jsOutput: CHILD got message: { hello: 'world' }Example 2: The filename is index.js JavaScript // Node.js program to demonstrate the // Process 'message' Event // Importing process module const cp = require('child_process'); // Initiating child process const process = cp.fork(`${__dirname}/sub.js`); // Message Event process.on('message', (m) => { console.log('PARENT got message:', m); }); // Causes the child to print: // CHILD got message: { hello: 'world' } process.send({ hello: 'world' }); Here the filename is sub.js JavaScript // Importing process module const process = require('process'); // Message Event process.on('message', (m) => { console.log('CHILD got message:', m); process.exit(0) }); // Causes the parent to print: // PARENT got message: { foo: 'bar', baz: null } process.send({ foo: 'bar', baz: NaN }); Run the index.js file using the following command: node index.jsOutput: CHILD got message: { hello: 'world' } PARENT got message: { foo: 'bar', baz: null }Reference: https://nodejs.org/dist/latest-v16.x/docs/api/process.html#process_event_message Comment More infoAdvertise with us Next Article Node.js Process message Event R rohitprasad3 Follow Improve Article Tags : Web Technologies Node.js Node.js-process-module Similar Reads 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 Node.js process.exit() Method The process.exit() method is used to end the process which is running at the same time with an exit code in NodeJS. Syntax: process.exit( code ) Parameter:  This function accepts single parameter as mentioned above and described below: Code: It can be either 0 or 1. 0 means end the process without a 2 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 warning Event The 'warning' is an event of class Process within the process module which is emitted whenever Node.js emits a process warning. Syntax: Event: 'warning'Parameters: This event does not accept any argument as a parameter. Return Value: This event returns nothing but a callback function for further ope 2 min read Node.js process.abort() Method The process.abort() property is an inbuilt application programming interface of the process module which is used to abort a running NodeJS process immediately. It also generates a core file. Syntax: process.abort() Parameter: This function does not accept any parameter. Return Type: It has a void re 2 min read Like