
Lesson 06 · 11 min
Async handlers and the database
The handler awaits the database. Express 5 delivers the error to the error handler by itself.
A real handler goes to the database, and that's asynchronous. In Express 5 a handler can be async: if the Promise rejects, Express passes the error to next(err) and on to the error handler. In Express 4 you had to do this by hand with try/catch and next(err) or a wrapper. Move database work into a repository or service, and keep request parsing and the response in the handler.
Sign in to continue
The rest of this lesson opens after sign up
The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.