{"id":17259,"library":"http-measuring-client","title":"Node.js HTTP Request Metrics Client","description":"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.","status":"abandoned","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/Floby/node-http-measuring-client","tags":["javascript","http","stats","outbound","measure","logs","monitoring"],"install":[{"cmd":"npm install http-measuring-client","lang":"bash","label":"npm"},{"cmd":"yarn add http-measuring-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-measuring-client","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS only and does not support ES module `import` syntax.","wrong":"import { create } from 'http-measuring-client';","symbol":"create","correct":"const httpMeasuringClient = require('http-measuring-client');\nconst http = httpMeasuringClient.create();"},{"note":"Used for instrumenting the Node.js native `https` module. CommonJS only.","wrong":"import { createSecure } from 'http-measuring-client';","symbol":"createSecure","correct":"const httpMeasuringClient = require('http-measuring-client');\nconst https = httpMeasuringClient.createSecure();"},{"note":"Allows monkey-patching the global Node.js `http` module, though the documentation advises against this approach. CommonJS only.","wrong":"import { mixin } from 'http-measuring-client';","symbol":"mixin","correct":"const httpMeasuringClient = require('http-measuring-client');\nhttpMeasuringClient.mixin(require('http'));"}],"quickstart":{"code":"const httpMeasuringClient = require('http-measuring-client');\nconst http = httpMeasuringClient.create();\n\nhttp.on('stat', (parsedUri, stats) => {\n  console.log(`Request to ${parsedUri.href} completed.`);\n  console.log(`Total Time: ${stats.totalTime}ms`);\n  console.log(`Connection Time: ${stats.connectionTime}ms`);\n  console.log(`Processing Time: ${stats.processingTime}ms`);\n  console.log(`Transmitting Time: ${stats.transmittingTime}ms`);\n});\n\n// Make an HTTP GET request and collect stats\nhttp.get('http://google.com', (response) => {\n  let data = '';\n  response.on('data', (chunk) => {\n    data += chunk;\n  });\n  response.on('end', () => {\n    console.log('Response from google.com received and ended.');\n    // console.log('Response body snippet:', data.substring(0, 100) + '...');\n  });\n}).on('error', (err) => {\n  console.error('Error during HTTP request:', err.message);\n});\n\n// Example with an HTTPS request (requires a different client instance)\nconst https = httpMeasuringClient.createSecure();\nhttps.get('https://example.com', (response) => {\n  response.on('data', () => {});\n  response.on('end', () => {\n    console.log('Response from example.com received.');\n  });\n}).on('error', (err) => {\n  console.error('Error during HTTPS request:', err.message);\n});\n","lang":"javascript","description":"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."},"warnings":[{"fix":"Consider using modern, actively maintained HTTP client libraries with built-in or plugin-based metric collection, such as `axios` with interceptors, `node-fetch` with custom agents, or OpenTelemetry integrations for Node.js.","message":"The `http-measuring-client` package is abandoned and has not been updated since 2014. It is unlikely to be compatible with recent Node.js versions, especially those introducing significant changes to the `http` module or new APIs like `fetch` and `http2`. Using unmaintained packages poses security risks and may lead to unexpected behavior.","severity":"breaking","affected_versions":">=1.0.1 (all versions)"},{"fix":"Ensure your project is configured for CommonJS, or use `const httpMeasuringClient = require('http-measuring-client');` in an ES module file to import it if your Node.js version supports mixing CJS and ESM.","message":"The package is CommonJS-only. Attempting to use `import` statements (ES modules) will result in a `ReferenceError: require is not defined` or similar errors in an ES module context. It must be consumed via `require()`.","severity":"gotcha","affected_versions":">=1.0.1 (all versions)"},{"fix":"Prefer creating and injecting `http-measuring-client` instances into specific HTTP client libraries (like `request.defaults({ httpModules: { 'http:': http } })`) rather than modifying global modules.","message":"The documentation explicitly states that monkey-patching the global `http` module using `.mixin(http)` is possible but 'not recommended'. This approach can lead to unforeseen side effects, conflicts with other modules, and make debugging difficult due to altering global behavior.","severity":"gotcha","affected_versions":">=1.0.1 (all versions)"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Rename your file to `.cjs`, or change your `package.json`'s `type` field to `\"commonjs\"`. Alternatively, use `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const httpMeasuringClient = require('http-measuring-client');` if you must use it within an ESM file.","cause":"Attempting to use `require('http-measuring-client')` in a file that is treated as an ES module (e.g., because of `\"type\": \"module\"` in `package.json` or `.mjs` extension).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure you are calling `httpMeasuringClient.create()` or `httpMeasuringClient.createSecure()` and assigning the result to a variable that you then use for making requests (e.g., `const http = httpMeasuringClient.create(); http.get(...)`). Verify no other module is interfering with the `http` object.","cause":"This error can occur if the `http-measuring-client` is not correctly initialized with a valid `http` module, or if a global monkey-patching attempt failed or was overwritten.","error":"TypeError: http.get is not a function (or similar 'not a function' error on http methods)"}],"ecosystem":"npm","meta_description":null}