Is there a way to access the time stamp of when a HTTP request is sent to a Node.js server?
Something like:
app.post('', function (req, res) {
console.log(req.date); //or
console.log(req.timestamp);
}
I tried out several things and already printed out the whole req object to the console, but didn't find a time stamp attribute. Do I have to send the timestamp manually? I thought it is already part of a HTTP request.
There is Date in request headers that can be used to retrieve timestamp.
If you are using Express-4.x you can use req.get(headerName)
to get it.
If you are using node http module try to do console.dir(req.headers)
. If its available you can get it from req.headers["Date"]
This all are valid provided your the timestamp is sent across network from client side. Do also inspect the request (Lets say Chrome Dev tool Network) and check what all headers are sent.