Node.js HTTP Request Metrics Client

1.0.1 · abandoned · verified Wed Apr 22

The `http-measuring-client` is a Node.js module, currently at version 1.0.1, designed to provide detailed timing statistics for outbound HTTP and HTTPS requests. Released around 2014, the project appears to be unmaintained, with its last copyright year being 2014, indicating an abandoned status. It offers a drop-in replacement for Node's native `http` and `https` modules, emitting a 'stat' event with granular timing data such as `totalTime`, `connectionTime`, `processingTime`, and `transmittingTime` (all in milliseconds) after each request completes. This allows developers to gain insight into network latency and server response times directly from the client without requiring external proxies. While it can integrate with popular HTTP clients like `request` and `superagent` by injecting its custom HTTP module, it also supports a less recommended global monkey-patching approach for broader coverage. Its primary differentiator is the direct integration into the HTTP client layer for metrics collection.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a measuring HTTP client, listen for 'stat' events to log detailed timing information, and make both HTTP and HTTPS requests.

const httpMeasuringClient = require('http-measuring-client');
const http = httpMeasuringClient.create();

http.on('stat', (parsedUri, stats) => {
  console.log(`Request to ${parsedUri.href} completed.`);
  console.log(`Total Time: ${stats.totalTime}ms`);
  console.log(`Connection Time: ${stats.connectionTime}ms`);
  console.log(`Processing Time: ${stats.processingTime}ms`);
  console.log(`Transmitting Time: ${stats.transmittingTime}ms`);
});

// Make an HTTP GET request and collect stats
http.get('http://google.com', (response) => {
  let data = '';
  response.on('data', (chunk) => {
    data += chunk;
  });
  response.on('end', () => {
    console.log('Response from google.com received and ended.');
    // console.log('Response body snippet:', data.substring(0, 100) + '...');
  });
}).on('error', (err) => {
  console.error('Error during HTTP request:', err.message);
});

// Example with an HTTPS request (requires a different client instance)
const https = httpMeasuringClient.createSecure();
https.get('https://example.com', (response) => {
  response.on('data', () => {});
  response.on('end', () => {
    console.log('Response from example.com received.');
  });
}).on('error', (err) => {
  console.error('Error during HTTPS request:', err.message);
});

view raw JSON →