Simplifying Code Flows with Promises
In this section, you’ll add another API to your lib/search.js file. Like the /search/books API from last section, this /suggest API will hit your Elasticsearch cluster for information, but this time we’ll use Promises rather than callbacks to manage asynchronous control flow.
For synchronous code this is good enough, but for asynchronous code we need a bit more. The Node.js core module callbacks ...