1.0.1 • Published 6 years ago
http-duration-client v1.0.1
http-duration-client
Measure duration (in milliseconds) for Node HTTP lifecycle events from various phases of HTTP:

- DNS lookup
- TCP/Socket connect
- TLS connect
- First byte
- Content transfer
- Total request
Development
- To check the HTTP lifecycle events, clone this repository
git clone git@github.com:congruencelabs/http-duration-client.git- Install the package dependencies using
yarn
yarn install- Run the
examples/client-with-duration.jsfile to see the lifecycle events being logged for a request tohttps://api.github.com/users
Usage
- Install the
http-duration-clientusingnpmoryarn
npm install http-duration-clientor
yarn add http-duration-client- 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
}