Using .exec() is simple, but you are limited to small-sized outputs, and you cannot also get a partial answer: let's see more about this. Imagine you are preparing a large file to be sent to a client. If you were to read that file with .exec(), you wouldn't be able to start sending the file contents to a client until you had read all the file. However, if the file were too large, that would not only imply a delay, but also the possibility of a crash. Using .spawn() gives you an interesting addition: the possibility of using streams to communicate, in a bidirectional way, with the spawned process.
Using spawn() to run a command, and communicating with it
How to do it...
Using .spawn() is similar to .exec() in general...