Replace callbacks with promises

- [Instructor] The key purpose of adding promises…to JavaScript was to provide an alternative way…to write asynchronous code.…In our demo project, we have quite a few places…where we're using the callback pattern…to handle asynchronous behavior.…So, in this video, we are going to replace…some of those callbacks with promises.…Let's start with a simple promise creation.…Open up quoteManager, which is in our lib folder.…And this module exports one function, updateQuotes,…which follows the callback pattern,…accepting a callback function as an argument,…and calling that with the data once complete.…

Let's use promises here instead.…We'll start on line 4 by removing the callback argument.…So now we've got updateQuotes in the function signature…and it has no arguments.…Then on line 5, we can make a new line.…And we're going to immediately return a function call…to the constructor for Promise.…So we'll return new Promise.…That constructor function…is going to take an anonymous function,…which we can use an arrow function for.…

Resume Transcript Auto-Scroll

Author

Released

3/24/2017

The next evolution of JavaScript came with the release of the ECMAScript 6 (ES6) specification—and Node.js is a place where you can leverage all the new language features introduced. In this course, discover many of the new ES6 features you can now use in Node.js. Instructor Ryan Lewis dives into new syntax such as arrow functions and default parameters, and covers destructuring, promises, generators, and much more. By walking through the process of converting a fully-functional Node.js web application written in pre-ES6 JavaScript, Ryan helps you gain first-hand experience with using these exciting new features. Plus, he shares valuable insights and provides context that helps you gain a robust understanding of all that ES6 has to offer.