This example reads lines from a child process one by one, as soon as lines become fully available. Related:
nodejs/read_child_process_lines.js
#!/usr/bin/env node
const childProcess = require('child_process')
const readline = require('readline')
const p = childProcess.spawn('./count.js', ['2'])
;(async function() {
const rl = readline.createInterface({ input: p.stdout })
for await (const line of rl) {
console.log(line)
}
})()