As promises get more and more complex, additional methods can be used to make their consumption cleaner and more readable. Scott explains how to error handle individual promise calls. He also introduces the all() method which will consume an array of promises.
(asian music)…- [Scott] So one thing to note here…is that whatever you return inside of a .then…is automatically wrapped in another promise for you.…So what that means is if I just return…the value hey,…I'm able to chain,…excuse me,…I'm able to chain another.then on here…because it returns a promise,…and I get the value of whatever the previous promise was…which will be like a word, which is hey.…
So then I can just console.log, word.…So if I run this, hey.…Whatever I return inside of a .then.…I can return something else in here,…and I could do .then as well.…That also means that I can also just return…other promises in here too, right?…So if I just wanted to return read file again,…and this time maybe it reads a different file,…I could do that.…
I could return a promise,…I could return a regular value.…Whatever I return here is going to be a promise.…So that's how you would deal with nested callbacks…and chaining of the promises.…Just make sure that you return something to one of these.…So a good pattern what people do…
This course was created by Frontend Masters. It was originally released on 12/30/2015. We're pleased to host this training in our library.
- Executing Node.js
- Using Express
- What is middleware?
- Testing in Node.js
- Using Mongo with Node.js
- Data modeling
- Querying data with Mongoose
- Identifying sensitive routes
- Configuring the deployment
Skill Level Intermediate
Node.js: Build Your First Microservicewith Daniel Khan2h 9m Intermediate
Building APIs Using Hapi in Node.jswith Kirsten Hunter2h 23m Intermediate
2. REST APIs
5. Organization and Configuration
7. Data Modeling
10. Securing Routes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.