The Child_process.fork() method is a special case of .spawn(), which specifically only spawns new Node processes. The spawned child process has a communication channel built in that makes it even simpler to pass messages between the parent process and itself: you just use the .send() method to send a message, and listen to the "message" event on the other side. Let's see how to fork off a second process, and communicate with the first one.
Using fork() to run Node commands
How to do it...
Since the code of the previous section used .spawn() to launch a new Node instance and run some code, it's fairly obvious that we can quickly and simply adjust it to use .fork() instead. Also, we won't have to use...