Node.js IPC between a Python parent and a Node.js child
07:05 08 Aug 2022

Node.js has integrated JSON-based IPC:

// main.js

const cp = require('node:child_process');
const n = cp.fork(`${__dirname}/sub.js`);

n.on('message', (m) => {
  console.log('PARENT got message:', m);
});

// Causes the child to print: CHILD got message: { hello: 'world' }
n.send({ hello: 'world' });
// sub.js

process.on('message', (m) => {
  console.log('CHILD got message:', m);
});

// Causes the parent to print: PARENT got message: { foo: 'bar', baz: null }
process.send({ foo: 'bar', baz: NaN });

How can I write main.js in Python? I understand that this isn't supported:

... using the IPC channel with a child process that is not a Node.js instance is not supported

But can it be done?

javascript python node.js ipc