IPC Communication between Node.js and Java


I’m looking to communicate between Node.js and a Java sub-process via IPC. I’m looking for recommendations that do not require opening a port.

const { spawn } = require('child_process')

// Java App is within args
const args = []

const javaProcess = spawn('java', args, { cwd: __dirname })

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

// Sends { 'hello': 'world' } to the Java process
javaProcess.send({ hello: 'world' })

I understand that the Node layer can send messages to a sub-process, I just don’t know how I’d go about listening for messages in the Java layer and sending messages back.

Any help is greatly appreciated, thanks!


I solved this issue by using named pipes…

On Node I used the Net API

On Java I used RandomAccessFile

Answered By – Mike Mulligan

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.