Open In App

Node.js process.channel Property

Improve
Improve
Like Article
Like
Save
Share
Report

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




// Node.js program to demonstrate the  
// Process.channel Property
  
// Importing process modules
const cp = require('child_process');
  
// Getting child process reference 
const process = cp.fork(`${__dirname}/sub.js`);
  
// Causes the child to print: 
// CHILD got message: { hello: 'world' }
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




// Node.js program to demonstrate the  
// Process.channel Property
  
// Importing process modules
const process = require('process');
  
// Getting process channel
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
Previous
Next
Share your thoughts in the comments
Similar Reads