# superagent-node-http-timings

> Superagent plugin for measuring http timings in node.js

Latest version **1.0.2** (published 2024-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install superagent-node-http-timings
pnpm add superagent-node-http-timings
yarn add superagent-node-http-timings
bun add superagent-node-http-timings
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-11-24 |
| First published | 2019-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.5.0 |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Maintainers | szarouski |
| Keywords | superagent, timings, http |

## Links

- npm: https://www.npmjs.com/package/superagent-node-http-timings
- Repository: https://github.com/webuniverseio/superagent-node-http-timings
- npm.io page: https://npm.io/package/superagent-node-http-timings

## Recent versions

- 1.0.2 (latest) — 2024-11-24
- 1.0.1 — 2019-11-09
- 1.0.0 — 2019-11-09

## README

```
yarn add superagent-node-http-timings
npm i --save superagent-node-http-timings
```

# HTTP Timings
This plugin for superagent gives you an easy interface to get http timings information. Primary use case is to be able to monitor and optimize network requests in node in a similar way to how you do it in browser with network inspector.

# Example
```js
const request = require('superagent');
const logNetworkTime = require('superagent-node-http-timings');
request
  .get(`https://google.com`)
  .use(logNetworkTime((err, result) => {
    if (err) {
      return console.error(err);
    }
    console.log(result);
  }))
  .then(x => x);
```
Sample results (timings are in milliseconds)1:
```json
{
  "status": 301,
  "timings": {
    "socketAssigned": 4.0982,
    "dnsLookup": 38.9614,
    "tcpConnection": 42.1931,
    "tlsHandshake": 105.221,
    "firstByte": 67.0892,
    "contentTransfer": 0.6482,
    "total": 258.2111
  },
  "url": "https://google.com"
}
```
 ## Results interpretation
  - `socketAssigned` - time since call was initiated until socket got assigned to request
  - `dnsLookup` - time since socketAssigned until dns lookup end, will be `undefined` when request was sent to IP (no domain)
  - `tcpConnection` - time since dnsLookup (or socketAssigned if IP was used) until connection was established
  - `tlsHandshake` - time since tcpConnection until until ssl negotiation end, will be `undefined` when request was sent via http
  - `firstByte` - time since tlsHandshake (or tcpConnection for http request) until first byte
  - `contentTransfer` - time since firstByte until response end  

# Inspired by 
 - https://blog.risingstack.com/measuring-http-timings-node-js/
 - https://github.com/RisingStack/example-http-timings
 
# Contributing to this repo
PRs are welcome! :)

---
_Source: https://npm.io/package/superagent-node-http-timings · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
