Package Exports
- https-timer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (https-timer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
https-timer
A lightweight, dependency-free Node.js module for timing HTTP/HTTPS requests.
Useful for determining the duration of different HTTPS phases:
- Socket Initialization
- DNS Lookup
- TCP Connection
- TLS Handshake
- Time to First Byte
- Content Transfer
Installation
$ npm install https-timer --save
Basic Usage
const httpsTimer = require('https-timer');
httpsTimer.get('https://www.google.com', (error, response) => {
if (!error && response) {
console.log(response.timing); // Prints the timing durations below
}
});
When a request has ended, a timing
object is added to the response
object.
Here is an example snapshot of the timing
object. The timing durations are in milliseconds:
{
"durations": {
"socketOpen": 1.579389,
"dnsLookup": 39.922508,
"tcpConnection": 28.770425,
"tlsHandshake": 218.159047,
"firstByte": 148.640706,
"contentTransfer": 1.954565,
"total": 439.02664
}
}
Request with custom options
Since httpsTimer
utilizes the native Node.js http
and https
modules, you can pass an options
object when making a request:
const httpsTimer = require('https-timer');
const options = {
url: 'https://api.github.com/repos/JoshCrozier/https-timer',
headers: {
'User-Agent': 'HTTPS Request Timer'
}
};
httpsTimer.get(options, (error, response) => {
if (!error && response && response.statusCode === 200) {
console.log('Response body: ', JSON.parse(response.body));
console.log('Response Timing: ', response.timing);
} else {
console.log('Request error: ', error);
}
});
License
Copyright (c) 2016-2018 Josh Crozier