-
-
Save lqqyt2423/a79a4c359abd0e101ab990b9eda1a0f4 to your computer and use it in GitHub Desktop.
进程间通信 node
This file contains hidden or 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
// IPC | |
// parent.js | |
'use strict'; | |
const cp = require('child_process'); | |
const n = cp.fork('./sub.js'); | |
n.on('message', function (m) { | |
console.log('PARENT got message:', m); | |
}); | |
n.send({ hello: 'world' }); | |
// sub.js | |
'use strict'; | |
process.on('message', function (m) { | |
console.log('CHILD got messae:', m); | |
}); | |
process.send({ foo: 'bar' }); | |
process.send('hello from child'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment