Giter Site home page Giter Site logo

Comments (3)

dougwilson avatar dougwilson commented on April 16, 2024

Thanks for reporting the issue! I'm not sure why this would be off hand. I can take a look if you can provide code and steps to reproduce the issue so I have something to investigate!

from response-time.

 avatar commented on April 16, 2024

Well one reason is that postman starts its own timer and so there is the clients network latency. Where as i believe this package is the response time from when it receives the request to when it send the response.

But i was suprised that the X-Response-Time and response(req,res,time) were different.

Sorry it is not a simple example, I have been using this package to add response time to my logger.

     app.use(responseTime());

     app.use(responseTime((req: Request, res: Response, time: any) => {

            const logId = uuid();

            console.log(req);

            const requestLog = {
                log_id: logId,
                line_data_method: req.method,
                line_data_path: req.originalUrl,
                line_data_host: req.hostname,
                line_data_url: req.hostname + req.originalUrl,
                message: ".",
            };

            this.log.info({ ...requestLog, ...{ log_type: "request" } });

            res.on("finish", () => {

                // console.log(res);

                const responseLog = {
                    log_id: logId,
                    line_data_statusCode: res.statusCode,
                    line_data_statusMessage: res.statusMessage,
                    line_data_responseTime: time,
                    line_data_responseTimeHeader: res.getHeader('x-response-time'),
                    message: "."
                };

                this.log.info({ ...responseLog, ...{ log_type: "response" } });

            });

        }));

from response-time.

dougwilson avatar dougwilson commented on April 16, 2024

Ah, I see what you mean. This is because each instance of responseTime middleware has it's own timer, which is why the times are not exactly the same.

from response-time.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.