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.

What is middleware?

What is middleware?

From the course: Learning Koa

Start my 1-month free trial

What is middleware?

- [Instructor] What is middleware? In the context of our Koa server, how would it be used? Basically, at its core, middleware are simply functions that perform specific actions in the server, like changing a date into a readable format before sending it back to the client. In this scenario, the client would be asking what is the date, then after the server return the date with the Javascript date function, the middleware will transform the date using Moment.js into something better for the client. Typically, middleware in an express server are inserted inside of a specific get call, for a route, and executed leveraging the request and response objects. Because it is using callback methods, it's also prone to the same problem we've mentioned earlier. No response from the function, could break the app. But in Koa, because it uses its own cascading approach, and also async and promises, the approach is a bit different. It uses a method called cascading, and leveraging promises, it moves…

Contents