
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
retry-simple
Advanced tools
Simplify async retries in JavaScript and TypeScript — supports exponential backoff, jitter, timeouts, and custom retry conditions.
A lightweight and flexible retry utility for asynchronous operations — built for Node.js and TypeScript.
shouldRetry)onRetry) after each failed attemptnpm install retry-simple
or using yarn:
yarn add retry-simple
import { retry } from "retry-simple";
let attempt = 0;
async function unstableOperation() {
attempt++;
if (attempt < 3) throw new Error(`Fail attempt ${attempt}`);
return "✅ Success on attempt " + attempt;
}
const result = await retry(unstableOperation, {
retries: 5,
delay: 500,
backoff: true,
jitter: true,
onRetry: (err, attempt) =>
console.log(`Attempt ${attempt} failed: ${(err as Error).message}`)
});
console.log(result);
const { retry } = require("retry-simple");
let attempt = 0;
async function unstableOperation() {
attempt++;
if (attempt < 3) throw new Error(`Fail attempt ${attempt}`);
return "✅ Success on attempt " + attempt;
}
retry(unstableOperation, {
retries: 5,
delay: 500,
backoff: true,
jitter: true,
onRetry: (err, attempt) =>
console.log(`Attempt ${attempt} failed: ${err.message}`)
})
.then(console.log)
.catch(console.error);
Attempt 1 failed: Fail attempt 1
Attempt 2 failed: Fail attempt 2
✅ Success on attempt 3
➕ See more advanced examples in MORE_EXAMPLES.md
retry(fn, options?)Runs an asynchronous function with automatic retry logic.
| Parameter | Type | Required | Description |
|---|---|---|---|
fn | () => Promise<T> | ✅ | The async function to execute. |
options | RetryOptions | ❌ | Optional configuration (see below). |
| Option | Type | Default | Description |
|---|---|---|---|
retries | number | 3 | Maximum number of retry attempts (excluding the first try). |
delay | number | 1000 | Initial delay between retries in milliseconds. |
backoff | boolean | false | Doubles the delay after each failed attempt (exponential backoff). |
jitter | boolean | false | Adds ±20% randomness to delay to prevent retry storms. |
maxDelay | number | undefined | Maximum allowed delay between retries. |
timeout | number | undefined | Timeout for each individual attempt (ms). |
onRetry | (error: unknown, attempt: number) => void | undefined | Callback executed after each failed attempt before retrying. |
shouldRetry | (error: unknown, attempt: number) => boolean | () => true | Custom logic to decide whether to continue retrying based on the error or attempt number. |
retries, delay, backoff, jitter, maxDelay, timeout, onRetry, shouldRetryIf you like this utility, consider giving it a ⭐ on GitHub!
Feedback and contributions are always welcome 🙌
© 2025 Theresa Lau — Released under the MIT License
FAQs
Simplify async retries in JavaScript and TypeScript — supports exponential backoff, jitter, timeouts, and custom retry conditions.
We found that retry-simple demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.