Scripting Audacity from Node

I’m attempting to control Audacity® from a Node process using mod-script-pipe.

Their example is in Python, and I would like to port that to Node.

For simplicity, I’d like to get a very basic test working on macOS Catalina.

What I have (ignoring error checking for now):

const os = require('os');
const fs = require('fs');

// Get the current user's identifier (part of the pipe)
const uidText = os.userInfo().uid.toString();
const TONAME = `/tmp/audacity_script_pipe.to.${uidText}`;
const FROMNAME = `/tmp/audacity_script_pipe.from.${uidText}`;
const EOL = "n";
const ENCODING = 'utf-8';

// Omitting the existence checks for brevity

const writeStream = fs.createWriteStream(TONAME, { encoding: ENCODING })

function sendCommand(command) {
  console.log(`Send: >>> ${command}`);
  writeStream.write(command + EOL);
}

sendCommand('Help: Command=Help');

Audacity 3.1.3 is installed and mod-script-pipe is enabled in Audacity preferences. Those pipes exist on my system.

If Audacity is running and I run this script, the script appears to work but Audacity crashes.

The Python script works fine; I suspect my port to Node streams is the issue. Can anyone provide a working example? It doesn’t have to be specific to Audacity if it shows how to port Python streams to Node.