Skip to content

Latest commit

 

History

History
36 lines (20 loc) · 1.24 KB

middlewares.md

File metadata and controls

36 lines (20 loc) · 1.24 KB

YES

Middlewares

Koa is essentially just an object containing an array of middleware generator functions. Middlewares is how you can really customize your Koa apps. Very pluggable since it works in a stack-like manner. It makes architecting your backend super fun!

You can inject middlewares by simply using .use().

Middlewares

Remember that Koa works in a stack-like manner so the order of where you put the middleware in your code matters!

Middleware order matters

You can move onto the next middleware in line by:

yield next;

You can see the cascading effect of how Koa's middlewares goes downstream then back upstream:

Koa Cascading Terminal Output

Challenge

Build your own error handler utilizing this down/up stream behavior of Koa middlewares!

Resource

Check out some cool middlewares for Koa here.


Prev: Directory Structure | Next: Routes | Home: Lecture Outline