54

GitHub - szmarczak/http-timer: Timings for HTTP requests

 5 years ago
source link: https://github.com/szmarczak/http-timer
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

http-timer

Timings for HTTP requests

Build Status Coverage Status install size

Inspired by the request package.

Usage

'use strict';
const https = require('https');
const timer = require('@szmarczak/http-timer');

const request = https.get('https://httpbin.org/anything');
const timings = timer(request);

request.on('response', response => {
	response.on('data', () => {}); // Consume the data somehow
	response.on('end', () => {
		console.log(timings);
	});
});

// { start: 1535183088427,
//   socket: 1535183088429,
//   lookup: 1535183088465,
//   connect: 1535183088602,
//   response: 1535183089049,
//   end: 1535183089050,
//   phases:
//    { wait: 2,
//      dns: 36,
//      firstByte: 447,
//      download: 1,
//      tcp: 137,
//      total: 623 } }

License

MIT


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK