I am a bit confused regarding the response time token that is printed from morgan middleware with nodejs. Via postman i see reponse time say 100+ms, but in the logs using the middleware, the response time is like 0.1 and around that. At a first glance this may look like i have divided by thousand to get the seconds value but i havent.
This is my code:
const morganMiddleware = morgan(
(tokens, req, res) => JSON.stringify({
method: tokens.method(req, res),
url: tokens.url(req, res),
status: Number.parseFloat(tokens.status(req, res)),
content_length: tokens.res(req, res, 'content-length'),
response_time: Number.parseFloat(tokens['response-time'](req, res)),
}),
{
stream: {
// Configure Morgan to use our custom logger with the http severity
write: (message) => {
const data = JSON.parse(message);
logger.http('incoming-request', data);
},
},
},
);
I am expecting the response time to be the same in postman and in the logger. If not exactly then atleast in the vicinity