/ live.thehmm.nl / back / node_modules / @szmarczak / http-timer /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]dist/2 years ago -  
[   ]LICENSE40 years ago1.0K 
[TXT]README.md40 years ago2.9Kd7c1522 post receive test [كارل مبارك]
[   ]package.json2 years ago2.4K 
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

Note:

  • The measured events resemble Node.js events, not the kernel ones.
  • Sending a chunk greater than highWaterMark will result in invalid upload and response timings. You can avoid this by splitting the payload into smaller chunks.
const https = require('https');
const timer = require('@szmarczak/http-timer');

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

request.once('response', response => {
    response.resume();
    response.once('end', () => {
        console.log(response.timings); // You can use `request.timings` as well
    });
});

// {
//   start: 1572712180361,
//   socket: 1572712180362,
//   lookup: 1572712180415,
//   connect: 1572712180571,
//   upload: 1572712180884,
//   response: 1572712181037,
//   end: 1572712181039,
//   error: undefined,
//   abort: undefined,
//   phases: {
//     wait: 1,
//     dns: 53,
//     tcp: 156,
//     request: 313,
//     firstByte: 153,
//     download: 2,
//     total: 678
//   }
// }

API

timer(request)

Returns: Object

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

If something has not been measured yet, it will be undefined.

License

MIT

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80