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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-fetch-retry-timeout

v1.2.1

Published

node-fetch with retries and timeout. Done right.

Readme

Yet Another node-fetch-retry-timeout (YANFRT)

Minimalistic drop-in replacement for node-fetch. Created because other alternatives were not good for me (and believe me: I really tried hard to avoid creating yet another node-fetch extra feature package).

Notable differences from default node-fetch behaviour:

  1. Default redirect strategy is 'manual' so we get 30x redirects as responses
  2. Response timeout is 20s
  3. Will consider each 50x response as a bad one and will retry (pass retryOnHttpResponse: false to disable)

Why, god, why?

Major differences from https://www.npmjs.com/package/@adobe/node-fetch-retry:

  1. In YANFRT, Retries are configured by amount of attempts and not by total allowed duration of request (more convenient when request latency is fluctuating between 1 and 20 seconds like in most of my use cases)
  2. One simple retry strategy: just amount of attempts and delay between requests
  3. No Apache OpenWhisk and no other fat

Differences compared to https://www.npmjs.com/package/fetch-retry :

  1. YANFRT is based on node-fetch
  2. More flexible retry on http response codes (not an array of codes but a callback so you can do (response.status >= 400 && response.status <= 600) || response.status == 302

Differences compared to https://www.npmjs.com/package/node-fetch-retry :

  1. YANFRT has timeouts handling based on AbortController
  2. Can retry based on http response statuses

Unique feature

Since version 1.2 YANFRT supports changing opts of request on each retry (via beforeRetry optional callback). This allows switching broken proxies. See /test/ folder ("can change agent on retry" test)

Installation

npm i node-fetch-retry-timeout

Example

  const fetch = require('node-fetch-retry-timeout')
  let response = await fetch('https://google.com', {
    method: 'GET', 
    retry: 2, // number attempts to retry
    pause: 500, // pause between requests (ms)
    timeout: 5000,  // timeout PER 1 REQUEST (ms)
    retryOnHttpResponse: r => r.status >= 500, // this is the default implementation of retryOnHttpResponse, pass false to disable
    beforeRetry: (retryNum, error) => { // switch opts on retry (retryNum == 1 before first retry is initiated, check the existence of error.response for advanced logic)
      return { headers: { 'Switch header': 'header-value' }, agent: SomeRandomAgent }
    }
  })

Running tests

npm run test