-
-
Save zeteticl/1e40587ff6f959483a38db8c09eddb88 to your computer and use it in GitHub Desktop.
NodeJS child_process communication (IPC) example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (process.send) { | |
process.send("Hello"); | |
} | |
process.on('message', message => { | |
console.log('message from parent:', message); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fork = require('child_process').fork; | |
const program = path.resolve('child.js'); | |
const parameters = []; | |
const options = { | |
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ] | |
}; | |
const child = fork(program, parameters, options); | |
child.on('message', message => { | |
console.log('message from child:', message); | |
child.send('Hi'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment