Optimizing asynchronous callbacks
Node.js is an runtime built for I/O heavy applications, and much of our code will involve asynchronous callbacks.
In the previous recipes in this chapter, we've explored how to determine a performance issue, locate the issue to single synchronous JavaScript functions and optimize that function.
Sometimes, however, a performance bottleneck can be part of an asynchronous flow, in these scenarios it can be difficult to pinpoint where the performance issue is.
In this recipe, we'll cover profiling and optimizing an asynchronous performance problem in depth.
Getting ready
In this recipe, we will optimize an HTTP API built on http://expressjs.com and https://www.mongodb.com.
We'll be using version 3.2, which we will need to install from the MongoDB https://www.mongodb.com website or via our systems package manager.
Note
MongoDB
For more on MongoDB (and on installing it) see Chapter 5, Persisting to Databases.
Once MongoDB is installed we can make a data directory for...