The `exponential-backoff` package provides a robust utility for retrying asynchronous (Promise-returning) functions with an exponential delay between attempts. Currently stable at version 3.1.3, the library maintains an active development status with regular chore and security updates, although it does not adhere to a strict release cadence. Its key differentiators include extensive configurability through the `BackOffOptions` object, allowing control over aspects like initial delay, maximum delay, number of attempts, jitter application (`full` or `none`), and a custom `retry` function for conditional reattempts. The package ships with TypeScript types, enhancing developer experience in TypeScript projects. It is designed to be a flexible solution for handling transient errors in network requests, database operations, or other unreliable processes.
npm install exponential-backoffVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `backOff` to retry an unreliable asynchronous function with custom exponential backoff options, including delay, attempts, jitter, and a custom retry condition.
Refer to the package's GitHub repository for the dedicated migration guide (`/doc/migration-guide.md`) to understand specific changes and update your code accordingly.
Explicitly define a `numOfAttempts` or implement a custom `retry` function that returns `false` under specific error conditions or after a certain number of attempts to prevent uncontrolled retries.
Ensure `numOfAttempts` is explicitly set to `1` or higher. For no retries, simply call the promise-returning function directly without `backOff`.
Ensure you are using standard ESM `import { backOff } from 'exponential-backoff';`. If using CommonJS, check your transpilation settings to ensure ESM imports are correctly handled or consider updating your build tools. In some cases, a package might not correctly expose its exports for CommonJS.Configure `numOfAttempts` to a finite, reasonable number. Alternatively, provide a custom `retry` function that checks the error (`e`) or `attemptNumber` and returns `false` to stop retrying when a certain condition is met (e.g., non-transient error, max attempts reached).
Review the `BackOffOptions` interface and the available options in the documentation. Correct any misspelled option names or remove unsupported properties from the options object.
No dependency data recorded yet.