Chapter 7. Child Processes

Running a Node instance in a single process works fine for a small application. As the application gets more complex and serves more users, a single process is not going to be enough to handle the increasing workload. No matter how powerful your server may be, a single thread can only support a limited load.

The fact that Node runs in a single thread does not mean that we can’t take advantage of multiple processes and, of course, multiple machines as well.

Using multiple processes is the best way to scale a Node application. Node is designed for building distributed applications with many nodes. This is why it’s named Node! Scalability is baked into the platform and it’s not something you start thinking about later in the lifetime of an application.

Introduction

We can easily create a child process in a main Node process using the "node:child_process" built-in module. These child processes can ...

Get Efficient Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.