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-wrapper

v1.1.0

Published

A simple wrapper for node-fetch

Readme

Build Status Dependencies Status

a wrapper for node-fetch

a simple wrapper for node-fetch, with support for timeout and retry. once enabled (maxAttempts set to > 1), it will

  • retry when request times out (this is unchangeable).
  • retry when request matches specific user-defined condition.

installation

npm install node-fetch-wrapper

test

npm test

general usage

// init a wrapper with base url http://example.com 
const FetchWrapper = require('node-fetch-wrapper');
const wrapper = new FetchWrapper('http://example.com', {
  // each request's timeout is 15 seconds
  timeout: 15000,
  // will try 3 times before finish
  maxAttempts: 3
  // wait for 1 seconds after each trial
  interval: 1000,
  // show debug info
  verbose: true,
  // retry on which condtion,
  retryCondition: defaultRetryCondition,
  // this function will be called before each retrying attempts. default unassigned.
  retryCallback: function (res) {
    console.log('callbacked');
  }
});

by default, the retryCondition has value:

function defaultRetryCondition(res) {
  const shouldRetryStatus =
    (res.status >= 100 && res.status <= 199) ||
    (res.status === 429) ||
    (res.status >= 500 && res.status <= 599);
  return shouldRetryStatus;
}

example

basically, this module acts like node-fetch (same input/output) with some additional support for timeout/retry


// identical to fetch('http://example.com/data')
wrapper.get('data');

// identical to fetch('https://example.com/write', { method: 'post', body: 'some body'}).
// note: general setting can be overwritten in specific request
wrapper.post('write', {
  body: 'some body',
  maxAttempts: 5
  retryCondition: function(res) {
    return res.body === 'fail';
  }
});

this module can also be used specifically for json:

const jsonWrapper = new FetchWrapper.json('http://example.com', {
  // each request's timeout is 15 seconds
  timeout: 15000,
  // will try 3 times before finish
  maxAttempts: 3
  // wait for 1 seconds after each trial
  interval: 1000,
  // show debug info
  verbose: true,
  // retry on which condtion,
  // default
  retryCondition: defaultRetryCondition
});

remember to specify json in the request, otherwise error will be thrown

const res = jsonWrapper.post('write', {
  body: 'some body',
  maxAttempts: 5
  json: {
    key1: 'value1'
  }
});

this does additional work that calls res.json() and assign the body back to res object.