Difference between spawn and exec of Node.js child_process
The most significant difference between child_process.spawn and child_process.exec is
in what they return -
spawn returns a stream and
exec returns a buffer.
... child_process.spawn is "asynchronously asynchronous",
meaning it starts sending back data ... as soon as the child process starts executing
child_process.exec returns the whole buffer output from the child process.
By default the buffer size is set at 200k.
If the child process returns anything more than that, your program will
crash with the error message "Error: maxBuffer exceeded".
... child_process.exec is "synchronously asynchronous", ...
it waits for the child process to end and tries to return all the buffered data at once