Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

node js - excecute a child process and exchange message to and from

// parent.js
const chPro = require('child_process');
const chFork = chPro.fork('child.js');
chFork.on('message', (msg) => {
  console.log('Message from child process => ', msg);
});
chFork.send({ hello: 'world' });

// child.js
process.on('message', (msg) => {
  console.log('Message from the parent => ', msg);
});

let counter = 0;
setInterval(() => {
  process.send({ counter: counter++ });
}, 1000);
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #node #js #excecute #child #process #exchange #message
ADD COMMENT
Topic
Name
5+3 =