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

node-fetch-retrier

v1.1.0

Published

A Node.js utility for performing fetch requests with customizable retry logic. Supports exponential backoff, error handling, and dynamic settings.

Downloads

5

Readme

Node Fetch Retrier Documentation

Overview

node-fetch-retrier is a utility for performing fetch requests with customizable retry logic. It allows developers to handle network errors and transient server issues gracefully by retrying requests based on specified conditions.


Installation

Install the package using npm:

npm install node-fetch-retrier

Usage

Basic Example

import { createNodeFetchRetrier } from 'node-fetch-retrier';

const retrier = createNodeFetchRetrier();

const response = await retrier('https://jsonplaceholder.typicode.com/posts/1', {
    retrierOptions: {
        maxAttempts: 3,
        delay: 1000,
        exponential: true,
    },
    nodeFetchOptions: {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
        },
    },
});

console.log(response);

API

createNodeFetchRetrier

Creates a retrier function for performing fetch requests with retry logic.

Parameters

  • options (optional): An object containing configuration options for the retrier.

Options

| Property | Type | Default | Description | | ------------- | ---------- | ---------------------- | -------------------------------------------------------------------------- | | title | string | "Fetch Retrier" | Title used for logging and debugging retry attempts. | | maxAttempts | number | 3 | Maximum number of retry attempts before giving up. Must be greater than 0. | | delay | number | 1000 | Delay in milliseconds between retries. Must be a positive number. | | exponential | boolean | true | Whether to use exponential backoff for the delay between retries. | | returnJson | boolean | true | If true, attempts to parse the response body as JSON. | | retryOn | function | Retry on status >= 500 | A function that determines whether to retry based on the response. | | log | function | No-op function | Logging function to track retry attempts. |

settings Property

Every retrier instance now has a settings property that exposes the current retrier options. This allows developers to inspect or modify the settings dynamically.


Retrier Function

The retrier function returned by createNodeFetchRetrier performs fetch requests with retry logic.

Signature

async function retrier(
    url: string,
    options: NodeFetchRetrierOptions
): Promise<NodeFetchRetrierResponseInit>

Parameters

  • url: The URL to fetch.
  • options: Configuration options for the fetch request.

NodeFetchRetrierOptions

| Property | Type | Description | | ------------------ | -------- | --------------------------------------------------------------------------- | | retrierOptions | object | Contains retry-related settings like maxAttempts, delay, and retryOn. | | nodeFetchOptions | object | Standard fetch options such as headers, method, and body. |


Return Value

A Promise that resolves to an object containing the following:

  • response: The final response object after retries, if applicable.
  • error: Details of any error encountered during retries.

Examples

Retry on Network Errors

const retrier = createNodeFetchRetrier();

const response = await retrier('https://example.com', {
    retrierOptions: {
        maxAttempts: 5,
        delay: 2000,
    },
    nodeFetchOptions: {
        method: 'GET',
    },
});

console.log(response);

Custom Retry Logic

const retrier = createNodeFetchRetrier({
    retryOn: (response) => response.status === 500 || response.status === 503,
});

const response = await retrier('https://example.com/fail', {
    retrierOptions: {
        maxAttempts: 3,
        delay: 1000,
    },
});

console.log(response);

Accessing settings Property

const retrier = createNodeFetchRetrier({
    title: "Custom Fetch Retrier",
});

console.log(retrier.settings); // Inspect the retrier's settings

retrier.settings.maxAttempts = 10; // Dynamically update settings

Testing

To test the package locally, use npm link:

cd /path/to/node-fetch-retrier
npm link
cd /path/to/test-project
npm link node-fetch-retrier

Run your test scripts in the test project.


Contributing

  1. Clone the repository.
  2. Install dependencies:
    npm install
  3. Build the project:
    npm run build
  4. Run tests:
    npm test

License

MIT License

Author

codebyolan golfbyolan olan88 Fredrik Olander