- [Narrator] When you are using Express,
you're going to hear the term middleware quite often.
What exactly do we mean when we say middleware?
According to the official Express documentation,
middleware functions are functions that have access
to the request object,
the response object and the next function
in the applications request response cycle.
Middleware performs a number of tasks,
executing code, changing the request in response objects,
ending the request response cycle,
or calling next.
The diagram here on the Express documentation
outlines the role of each aspect
of a middleware function call,
each of which we have discussed up to this point.
Now that we have a better understanding
of the term middleware,
let's head back to our editor and take a look at the
middleware that we've written up to this point.
In our index.js file, if you scroll down to around line 48,
where we created a get route that incorporated
routing parameters,
you can see that I've added a few comments
to help further explain the concept of middleware.
Effectively, all of our code above handling the response
is considered middleware.
In this particular example,
we access the routing parameters via the request object
and utilize that data to render the response
that we send to the client.
Middleware can come in a number of forms.
Some is built in to Express.
Some helps us handle errors,
and we can even add third-party middleware
to our applications.
In the next few videos,
we will explore each of these concepts more in depth.