From the course: Learning Koa
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Finalize cascading example
- [Instructor] Let's continue working on our code and finalize it, so now that we have our response, we have a log, we definitely need the response time middleware that we need to create, so let's go ahead and do that, so again, like we've done twice already, we need to start our middleware with app.use and also make it async and also pass next and ctx like so. Again, I'm using ES6 syntax, so if this is not familiar to you, this is the equivalent of doing something like this. But I prefer the ES6 syntax, so I'm doing this. So, once we have this set up, what we need to do is create a variable and I'm going to call this one start. And we're going to get the time, so by doing date.now. Then we're going to await, so what's going to happen if we await at this stage? This particular middleware is going to create a variable with date.now start. Then it's going to wait, therefore pass to all the other, so it's going to pass to the response or pass to this guy. So, while it does that, we have…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.