In this video, Emmanuel Henri demonstrates how to set up async in a back-end project.
- [Instructor] So now that we understand what async is,…let's look at code examples.…And as mentioned before,…you'll see it's very easy to use async in your code,…so let me demonstrate.…Let's get back to VS Code,…and the first thing we're going to do…is change some of the code that we have in our response.…We don't need to change anything with our context user data…but we're going to change something here.…The first thing we'll need to do is add the async keyword…inside of our function, app.use, here.…And then what we're going to do is primarily…the same thing that we've done here,…so we're going to pass ctx inside of that function,…and then use it inside of the async function now.…
And the async function works this way,…because we're using asynchronous in our function,…we need to try something so that's the syntax…that typically goes with promises, so you'll do a try,…and if within that try,…or the function that we need to try here,…doesn't work then we can catch it with an error,…and that's typically how it works.…
- What's Koa?
- Similarities and differences between Koa and Express
- What's a Koa Context?
- Throwing errors with Context
- Using async with Koa
- Cascading middleware