Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript What is Express Middleware?

Jeffrey Holcomb
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeffrey Holcomb
Full Stack JavaScript Techdegree Graduate 17,506 Points

What exactly is happening in the animation?

If I ignore the animation altogether, middleware seems pretty straightforward. A request comes in, middleware acts on it, and a response is sent back. However, the animation makes me feel like I don't understand what's happening. What does the arm that picks up one of the objects and shakes it around represent? And what does the apparatus that packages one of the objects represent? And how come each set of objects that arrives on the conveyor belt arrive in a different color order than the previous set? I know I'm probably looking too much into this, but the animation has got me second guessing my understanding of middleware.

I have to admit, I had the same feeling - but as has already been said in the answer to this question, I believe it is simply an illustration of 'Something Enters (Request) -> An action is made (Middleware) -> Something Exits (Response)'. In my opinion, could probably have been easier to understand, if it was illustrated as a Fast Food Restaurant;

A customer arrived with an order (Request) -> The order is being processed in the kitchen (Middleware) -> The food is given to the customer (Response).

This also includes the very neat visual of the 'Server' being the employee who 'serves' the food.

1 Answer

I think it is showing that middleware can do lots of different things in response to a request (in the animation the machine can inspect, shake, or smash) but that it still happens between the request and response. The items coming in on the conveyor belt can enter or leave as the requests/responses are made and don't have to stop and wait.