javascript – Req and Res in nodejs, problem understanding arguments

Question:

I found myself with the problem to fully understand what res and req mean in node js, but you need to understand the problem, I understand everything about what res is, and what is req and I know what it is used for. them, but a function, for example, function sum(x, y) it receives arguments x and y so that inside its body it does the sum process and then we can use the result, OK!

But in the case of req and res, the req is, as the name says, a request, and the res is the answer to that, so in my head it doesn't make any sense for the function to receive the request and the answer.

The question that remains is, how is this processed in the machine?

For me the concept that remains is, I arrive at a bakery and want salt bread, but first I have to ask if there is salt bread, but I already know there is salt bread, so I ask the baker at the same time I give the answer to him, and then I wait for him to answer me something I already answered him.

At least that's how it was understood, and I know it's wrong.

Answer:

It is in this case the expression of the function uses the HTTP protocol, which is based on req uisição and put res, then the req is an object that contains information about the HTTP request event, header information, try taking a console.log(req) , since res is basically the object that contains the server's response.

Scroll to Top