Req -> Http (https) Request Object.
You can get the request query, params, body, headers and cookies from it.
You can overwrite any value or add anything there.
However, overwriting headers or cookies will not affect the output back to the browser.
Res -> Http (https) Response Object.
The response back to the client browser.
You can put new cookies value and that will write to the client browser (under cross domain rules)
Once you res.send() or res.redirect() or res.render(), you cannot do it again, otherwise, there will be uncaught error.
req = {
_startTime : Date,
app : function(req,res){},
body : {},
client : Socket,
complete : Boolean,
connection : Socket,
cookies : {},
files : {},
headers : {},
httpVersion : String,
httpVersionMajor : Number,
httpVersionMinor : Number,
method : String, // e.g. GET POST PUT DELETE
next : function next(err){},
originalUrl : String, /* e.g. /erer?param1=23¶m2=45 */
params : [],
query : {},
readable : Boolean,
res : ServerResponse,
route : Route,
signedCookies : {},
socket : Socket,
url : String /*e.g. /erer?param1=23¶m2=45 */
}
res = {
app : function(req, res) {},
chunkedEncoding: Boolean,
connection : Socket,
finished : Boolean,
output : [],
outputEncodings: [],
req : IncomingMessage,
sendDate : Boolean,
shouldkeepAlive : Boolean,
socket : Socket,
useChunkedEncdoingByDefault : Boolean,
viewCallbacks : [],
writable : Boolean
}
function (req, res) {...}that is passed to createServer. They are effectively local variables of the function. createServer will then call the function, passing values to those variables, which are used by the function, e.g.res.writeHead(...)uses the value passed to res (hopefully an object with a writeHead method).