{"id":17373,"library":"superagent-node-http-timings","title":"Superagent HTTP Timings Plugin for Node.js","description":"superagent-node-http-timings is a superagent plugin designed for Node.js environments to capture detailed HTTP request timing information. It provides granular metrics such as `socketAssigned`, `dnsLookup`, `tcpConnection`, `tlsHandshake`, `firstByte`, and `contentTransfer`, culminating in a `total` request duration. This allows developers to monitor and optimize network performance in Node.js applications, similar to a browser's network inspector. The current stable version is `1.0.2`, with recent updates addressing issues like HTTP keep-alive. While not a high-cadence package, it receives targeted fixes as needed, indicating active maintenance. Its key differentiator is providing a comprehensive breakdown of network timings specifically integrated into the `superagent` request flow for server-side environments.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/webuniverseio/superagent-node-http-timings","tags":["javascript","superagent","timings","http"],"install":[{"cmd":"npm install superagent-node-http-timings","lang":"bash","label":"npm"},{"cmd":"yarn add superagent-node-http-timings","lang":"bash","label":"yarn"},{"cmd":"pnpm add superagent-node-http-timings","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a plugin for superagent and requires it as a peer dependency for functionality.","package":"superagent","optional":false}],"imports":[{"note":"This package is distributed as a CommonJS module. For ESM projects, you will typically need to use a default import: `import logNetworkTime from 'superagent-node-http-timings';` or configure your bundler.","wrong":"import { logNetworkTime } from 'superagent-node-http-timings';","symbol":"logNetworkTime","correct":"const logNetworkTime = require('superagent-node-http-timings');"}],"quickstart":{"code":"const request = require('superagent');\nconst logNetworkTime = require('superagent-node-http-timings');\n\nasync function makeTimedRequest() {\n  try {\n    const response = await request\n      .get(`https://google.com`)\n      .use(logNetworkTime((err, result) => {\n        if (err) {\n          console.error('Timing error:', err);\n          return;\n        }\n        console.log('HTTP Timings:', result);\n      }));\n    console.log('Request completed with status:', response.status);\n  } catch (error) {\n    console.error('Request failed:', error.message);\n  }\n}\n\nmakeTimedRequest();","lang":"javascript","description":"This example demonstrates how to use the superagent-node-http-timings plugin to log detailed HTTP network timings for a GET request to google.com."},"warnings":[{"fix":"For ESM, use `import logNetworkTime from 'superagent-node-http-timings';`","message":"This package is a CommonJS module. If you are working in an ES Modules (ESM) environment, direct named imports (`import { ... } from 'pkg'`) will not work. You will need to use a default import or a bundler to consume it correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install superagent: `npm install superagent` or `yarn add superagent`.","message":"The `superagent` package is a peer dependency. Ensure you have `superagent` installed in your project, and be aware of potential compatibility issues with very old or very new versions of `superagent`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Handle errors explicitly within the callback: `logNetworkTime((err, result) => { if (err) { console.error(err); return; } ... });`","message":"The timing callback function uses a Node.js-style error-first callback. Modern asynchronous code often prefers Promises or async/await. Ensure proper error handling within this callback, or wrap the `use` call in a Promise for easier integration with `async/await`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"For ESM, use `import logNetworkTime from 'superagent-node-http-timings';` and ensure your `package.json` has `\"type\": \"module\"` or the file uses the `.mjs` extension.","cause":"Attempting to use `require()` in an ES Modules (ESM) file.","error":"TypeError: require is not a function"},{"fix":"Ensure you are directly importing the default export: `import logNetworkTime from 'superagent-node-http-timings';`","cause":"Incorrect default import when the module's main export is a function (often happens with default CJS export imported as named in ESM).","error":"TypeError: (0 , _superagentNodeHttpTimings.default) is not a function"},{"fix":"Install superagent: `npm install superagent` or `yarn add superagent`.","cause":"`superagent` peer dependency is not installed.","error":"Error: Cannot find module 'superagent'"}],"ecosystem":"npm","meta_description":null}