{"library":"node-fetch-retry","title":"node-fetch-retry","description":"node-fetch-retry is a lightweight wrapper library designed to enhance `node-fetch` with automatic retry capabilities. It enables developers to specify a fixed number of retry attempts for network requests, introduce a pause duration between retries, and execute a custom callback function before each attempt. The current stable version is 2.0.1. Its release cadence appears to be infrequent, with the last notable activity several years ago, suggesting it is in maintenance mode or effectively abandoned. This library differentiates itself by offering a straightforward, integrated retry mechanism directly within the `fetch` options, making it a simple choice for adding basic request resilience without complex configurations often found in more feature-rich alternatives. It's best suited for Node.js environments requiring basic retry logic for transient network failures.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install node-fetch-retry"],"cli":null},"imports":["const fetch = require('node-fetch-retry');","const fetch = (...args) => import('node-fetch-retry').then(({ default: fetch }) => fetch(...args));"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as process from 'process';\n\nconst fetch = require('node-fetch-retry');\n\nasync function fetchDataWithRetry() {\n  const targetUrl = 'https://httpstat.us/503?sleep=1000'; // Example URL that returns 503 after a delay\n  const retries = 3;\n  const pauseMs = 1000; // 1 second pause\n\n  console.log(`Attempting to fetch from ${targetUrl} with ${retries} retries...`);\n\n  try {\n    let opts = {\n      method: 'GET',\n      retry: retries,\n      pause: pauseMs,\n      callback: (retryAttempt) => {\n        console.log(`Retry attempt: ${retryAttempt}. Waiting ${pauseMs}ms before next attempt.`);\n      },\n      silent: false // Set to true to suppress pause messages\n    };\n\n    // Make the fetch request with retry options\n    const res = await fetch(targetUrl, opts);\n\n    if (res.ok) {\n      const text = await res.text();\n      console.log('Fetch successful after retries!');\n      console.log('Response:', text.substring(0, 100) + '...');\n    } else {\n      console.error(`Fetch failed after all retries with status: ${res.status}`);\n    }\n  } catch (error) {\n    console.error('An unhandled error occurred during fetch operation:', error.message);\n  }\n}\n\nfetchDataWithRetry();\n","lang":"javascript","description":"Demonstrates fetching a URL with a specified number of retries and a pause between attempts, including a callback to log each retry attempt.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}