I am trying to pipe a large array from child process to parent process. It is about 200,000 * 100 * 2
number of elements in an array. I possibly need to pass even greater value in the future.
The below is my child process for passing the array to the parent process
process.on('message', (msg) => {
// console.log('inside child class');
excelParserTool(msg).then((result)=>{
process.stdout.write(JSON.stringify(result));
process.exit();
})
});
result
is the large array that it sends to the parent process
the below is the parent process which receives the array and processes it.
excelParserChild.stdout.on('data', (data) => {
excelBuffer += data
});
excelParserChild.stderr.on('data', (error) => {
console.log('stderr');
console.log(error);
errorFinal += error;
console.log(errorFinal)
});
excelParserChild.on('close', (exitCode) => {
console.log(excelBuffer);
})
This causes
(node:1468) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RangeError: Invalid string length
(node:1468) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code
I have tried using process.send(result)
to try to send the array also but it causes the same error. Now I am wondering if this even is the correct way of passing large data from child to parent process. What is the best methodology of passing large variable from child process to parent process? If I am doing it right, how do I solve invalid string length issue? Thanks.