CHAPTER 10

image

Simplifying Callbacks

The evented/asynchronous nature of Node.js means that it is possible to end up with deeply nested callbacks. There are various strategies in JavaScript that help reduce the callback nesting. In this chapter, we will explore these patterns. These help maintain readability, but more importantly these strategies will help decrease the likelihood of bugs creeping up on you. I promise.

The Callback Hell

Note that as we explore this section, it might seem like the situation is dire. Don’t worry. When we look at promises in the next section, you will find the pot of gold at the end of the rainbow.

An obvious issue with ...

Get Beginning Node.js now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.