Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-duration-client

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-duration-client

Measure duration for Node HTTP lifecycle events

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

http-duration-client

Measure duration (in milliseconds) for Node HTTP lifecycle events from various phases of HTTP:

Http lifecycle

  • DNS lookup
  • TCP/Socket connect
  • TLS connect
  • First byte
  • Content transfer
  • Total request

Build Status

Development

  1. To check the HTTP lifecycle events, clone this repository
git clone git@github.com:congruencelabs/http-duration-client.git
  1. Install the package dependencies using yarn
yarn install
  1. Run the examples/client-with-duration.js file to see the lifecycle events being logged for a request to https://api.github.com/users

Usage

  1. Install the http-duration-client using npm or yarn
npm install http-duration-client

or

yarn add http-duration-client
  1. Make an http request to an endpoint as shown in example below
const { requestWithDuration } = require('http-duration-client');

requestWithDuration({
        url: "https://api.github.com/users",
        headers: {
            'User-Agent': 'Example'
        },
        timeout: 500
    }), (err, res) => {
        if(err) {
            console.error(err);
        } else {
            console.log(res.duration);
        }
});

The result of the above should look similar to

{ 
    "dnsLookup": 62.253469,
    "tcpConnection": 20.589025,
    "tlsHandshake": 44.643525,
    "firstByte": 490.091997,
    "contentTransfer": 15.480998,
    "total": 633.059014
}

You can also use it with async and await requestWithDuration() or requestWithDuration().then()

(async () => {
    try {
        const resp = await requestWithDuration(
            {
              url: "https://api.github.com/users",
              headers: {
                "User-Agent": "Example"
              },
              timeout: 500
            },
        );
        console.log(resp.duration)
    } catch(err) {
        console.error(err)
    }
})()

The result of the above should look similar to

{ 
    "dnsLookup": 62.253469,
    "tcpConnection": 20.589025,
    "tlsHandshake": 44.643525,
    "firstByte": 490.091997,
    "contentTransfer": 15.480998,
    "total": 633.059014
}

Keywords

FAQs

Package last updated on 10 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc