Skip to content
Timings for HTTP requests
Branch: master
Clone or download
Latest commit 421d049 Apr 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
source
.editorconfig Initial commit Aug 24, 2018
.gitignore Rewrite in TypeScript, require Node 8, use `undefined` instead of `null` Apr 20, 2019
.npmrc Initial commit Aug 24, 2018
.travis.yml Rewrite in TypeScript, require Node 8, use `undefined` instead of `null` Apr 20, 2019
LICENSE Initial commit Aug 24, 2018
README.md Rewrite in TypeScript, require Node 8, use `undefined` instead of `null` Apr 20, 2019
package.json 2.0.0 Apr 20, 2019
test.ts Rewrite in TypeScript, require Node 8, use `undefined` instead of `null` Apr 20, 2019
tsconfig.json Rewrite in TypeScript, require Node 8, use `undefined` instead of `null` Apr 20, 2019

README.md

http-timer

Timings for HTTP requests

Build Status Coverage Status install size

Inspired by the request package.

Installation

NPM:

npm install @szmarczak/http-timer

Yarn:

yarn add @szmarczak/http-timer

Usage

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

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: 1535708511443,
//   socket: 1535708511444,
//   lookup: 1535708511444,
//   connect: 1535708511582,
//   upload: 1535708511887,
//   response: 1535708512037,
//   end: 1535708512040,
//   phases:
//    { wait: 1,
//      dns: 0,
//      tcp: 138,
//      request: 305,
//      firstByte: 150,
//      download: 3,
//      total: 597 } }

API

timer(request)

Returns: Object

  • start - Time when the request started.
  • socket - Time when a socket was assigned to the request.
  • lookup - Time when the DNS lookup finished.
  • connect - Time when the socket successfully connected.
  • upload - Time when the request finished uploading.
  • response - Time when the request fired the response event.
  • end - Time when the response fired the end event.
  • error - Time when the request fired the error event.
  • phases
    • wait - timings.socket - timings.start
    • dns - timings.lookup - timings.socket
    • tcp - timings.connect - timings.lookup
    • request - timings.upload - timings.connect
    • firstByte - timings.response - timings.upload
    • download - timings.end - timings.response
    • total - timings.end - timings.start or timings.error - timings.start

If something is not measured yet, it will be undefined.

Note: The time is a number representing the milliseconds elapsed since the UNIX epoch.

License

MIT

You can’t perform that action at this time.