main.js
const { spawn } = require("child_process");
const childProcess = spawn("node", [`${__dirname}/child.js`], { stdio: ["pipe", "pipe", "pipe"] });
childProcess.stdout.on("data", (message) => {
console.log(message.toString());
});
childProcess.stdin.write("main-message-stdio");
child.js
process.stdin.on("data", (message) => {
console.log(message.toString());
process.exit(0)
});
process.stdout.write("child-message-stdio");
main.js
const { spawn } = require("child_process");
const childProcess = spawn("node", [`${__dirname}/child.js`], { stdio: ["inherit","inherit","inherit", "ipc"] });
childProcess.on("message", (message) => {
console.log("[Main] received:", message);
});
childProcess.send("main-message-ipc");
child.js
process.on("message", (message) => {
console.log("[Child] received:", message);
process.exit(0)
});
process.send("child-message-ipc");