Node.js process.channel Property
The process.channel is an inbuilt application programming interface of class Process within the process module which is used to get the reference to the IPC channel. If no IPC channel exists, this property is undefined.
Syntax:
const process.channel
Parameters: This api takes no argument as a parameter.
Return Value: This api returns the reference to the IPC channel. If no IPC channel exists, this property is undefined.
Example 1:
index.js
const cp = require( 'child_process' );
const process = cp.fork(`${__dirname}/sub.js`);
process.send({ hello: 'world' });
console.log(process.channel)
|
sub.js
process.on( 'message' , (m) => {
console.log( 'CHILD got message:' , m);
process.exit()
});
|
Run the index.js file using the following command:
node index.js
Output:
Control {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
}
CHILD got message: { hello: 'world' }
Example 2:
index.js
const process = require( 'process' );
if (process.channel)
console.log( "Process Channel exist" )
else
console.log( "Process Channel doesn't exist" )
|
Run the index.js file using the following command:
Output:
Process Channel doesn't exist
Reference: https://nodejs.org/dist/latest-v16.x/docs/api/process.html#process_process_channel
Last Updated :
25 May, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...