http-duration-client
v1.0.1
Published
Measure duration for Node HTTP lifecycle events
Downloads
2
Maintainers
Readme
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 [email protected]:congruencelabs/http-duration-client.git
- Install the package dependencies using
yarn
yarn install
- Run the
examples/client-with-duration.js
file to see the lifecycle events being logged for a request tohttps://api.github.com/users
Usage
- Install the
http-duration-client
usingnpm
oryarn
npm install http-duration-client
or
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
}