Threw nodejs,I have a problem in calculating express api response time.
instead of using middlewares like morgan and winston using app.use(). I need a way to log response time inside api scope and send it as a response.
like :
app.post('/api', function (req: Request, res:Response) {
...
res.json({responseTime,data})
})
I have tried response-time package and stackoverflow question solutions but they were not helpful.
In fast responses that take less than 100ms, I see different response time in postman and my node server console.(e.g. postman:130ms , node server: 3ms)
how can I calculate the response time accurately?
There are different ways to use it. But one way of the ways most used is using morgan. Of course, you can see response time on only dev mode.
After you added like that, you should see a screen like that on terminal.