I see code like below in almost every NodeJS application:
const express = require("express");
const app = express();
app.post("/some-route", (req, res) => {
const data = req.body;
}
What I can not understand is where does the res
come from? I can understand req
comes from with the request that user/client application sends to the backend app, but what is this res
object we should pass to the callback function almost always we want to write such a route handler function?
Isn't res
what we should make in our handler function and send it back to the user? If so, how can we receive it as an input in our callback function?
Is this correct to say "Whenever the Express server receives a new request, it automatically creates a response object, and gives us the option to manipulate/modify this res object through the callback function? So we can either use this option and do something on that, then send it back to the client, or do nothing and express will send it's default or automatically created response back to the user"?
If so, what does a default express res
object look like?