npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

http-fetch-retry

v2.0.0

Published

HttpClient con reintento nativo en fetch Node.js

Downloads

125

Readme

http-fetch-retry

http-fetch-retry es una librería ligera para Node.js que extiende el fetch nativo agregando:

  • 🔁 Reintentos automáticos con backoff exponencial + jitter
  • ⏱ Timeout por request usando AbortController
  • 🧠 Manejo seguro de errores de red y timeouts
  • 🧩 Compatibilidad total con fetch nativo (retorna Response)

⚠️ Desde v2.x, fetchWithRetry retorna un Response nativo y NO lanza errores por status 4xx/5xx.

Compatible con: - Node.js 18+ - ESM - CommonJS


Instalación

npm install http-fetch-retry

Uso

ESM

import { HttpClient } from 'http-fetch-retry';

const res = await HttpClient.fetchWithRetry({
  method: 'GET',
  url: 'https://api.example.com',
});

if (!res.ok) {
  console.error('HTTP error:', res.status);
}

const data = await res.json();
console.log(data);

CommonJS

const { HttpClient } = require('http-fetch-retry');

const res = await HttpClient.fetchWithRetry({
  method: 'GET',
  url: 'https://api.example.com',
});

const data = await res.json();
console.log(data);

API

HttpClient.fetchWithRetry(request, options)

Extiende fetch nativo agregando reintentos y timeout.

Retorna

Promise<Response>{=html} (Response nativo)

No parsea automáticamente JSON.


Parámetros

request

Objeto compatible con fetch:

{
  url: string,               // requerido
  method?: string,           // default: GET
  headers?: object,
  body?: any
}

options

{
  timeoutMs?: number,        // default 30000
  maxRetries?: number,       // default 3
  baseDelayMs?: number,      // default 300
  maxDelayMs?: number,       // default 5000
  retryStatusCodes?: number[], // default [408,429,500,502,503,504]
  logger?: function
}

Comportamiento de Retry

Reintenta automáticamente cuando:

  • Status HTTP: 408, 429, 500, 502, 503, 504
  • Error de red (TypeError)
  • Timeout (AbortError)

No reintenta si: - maxRetries = 0 - El body no es reutilizable (ej: streams)


Timeout

Internamente usa AbortController.

Si ocurre timeout se lanza:

  • FetchTimeoutError

Errores disponibles

  • FetchTimeoutError
  • FetchRetryError
  • FetchResponseError
  • HostAuthenticationError
  • HostRequestTimeoutError

Todos heredan de CustomError.


Testing

npm test

Cobertura:

npm run test:coverage

Breaking Changes

v2.0.0

  • fetchWithRetry ahora retorna Response nativo
  • Ya no parsea JSON automáticamente
  • Ya no lanza error por status 4xx/5xx
  • Comportamiento alineado 100% con fetch

Migración:

Antes:

const data = await HttpClient.fetchWithRetry(...);

Ahora:

const res = await HttpClient.fetchWithRetry(...);
const data = await res.json();

Licencia

MIT