I have a nodejs parent process that starts up another nodejs child process. The child process executes some logic and then returns output to the parent. The output is large
I was running into the same issue and used the {end:false} option to fix the error. Unfortunately the accepted answer works only while handling discrete writes of short amounts of data. In case you have a lot of data (rather than just short messages), you need to handle flow control and using the .write() is not the best. For scenarios like this (large data transfers), its better you use the .pipe() function as originally in your code to handle flow control.
The error is thrown because the readable stream in your parent process is trying to end and close the writable stream input pipe of your child process. You should use the {end: false}
option in the parent process pipe:
Original Code:
require('streamifier').createReadStream('test 2').pipe(child.stdio[3]);
Suggested Modification:
require('streamifier').createReadStream('test 2').pipe(child.stdio[3], {end:false});
See details here from the NodeJs documentation: https://nodejs.org/dist/latest-v5.x/docs/api/stream.html#stream_readable_pipe_destination_options
Hope this helps someone else facing this problem.