Chapter 8. Child processes: Integrating external applications with Node

 

This chapter covers

  • Executing external applications
  • Detaching a child process
  • Interprocess communication between Node processes
  • Making Node programs executable
  • Creating job pools
  • Synchronous child processes

No platform is an island. Although it would be fun to write everything in JavaScript, we’d miss out on valuable applications that already exist in other platforms. Take GraphicsMagick, for instance (http://www.graphicsmagick.org/): a full-featured image manipulation tool, great for resizing that massively large profile photo that was just uploaded. Or take wkhtmltopdf (http://wkhtmltopdf.org/), a headless webkit PDF generator, perfect for turning that HTML report into a PDF download. In Node, the child_process module allows us to execute these applications and others (including Node applications) to use with our programs. Thankfully, we don’t have to re-invent the wheel.

The child_process module provides four different methods for executing external applications. All methods are asynchronous. The right method will depend on what you need, as shown in figure 8.1.

Figure 8.1. Choosing the right method

8.1. Executing external applications

8.2. Executing Node programs

8.3. Working synchronously

8.4. Summary