Gathering detailed insights and metrics for nice-retry
Gathering detailed insights and metrics for nice-retry
🦜 Type-safe, lightweight retry utility for async operations that simply works.
npm install nice-retry
Typescript
Module System
Node Version
NPM Version
69.1
Supply Chain
98.2
Quality
89
Maintenance
100
Vulnerability
100
License
TypeScript (98.08%)
JavaScript (1.92%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
1,204
Last Day
2
Last Week
9
Last Month
114
Last Year
1,204
MIT License
1 Stars
40 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Feb 10, 2025
Minified
Minified + Gzipped
Latest Version
0.3.7
Package Id
nice-retry@0.3.7
Unpacked Size
24.45 kB
Size
6.24 kB
File Count
7
NPM Version
10.8.2
Node Version
20.18.2
Published on
Feb 08, 2025
Cumulative downloads
Total Downloads
Last Day
100%
2
Compared to previous day
Last Week
-25%
9
Compared to previous week
Last Month
-89.5%
114
Compared to previous month
Last Year
0%
1,204
Compared to previous year
A lightweight, zero-dependency retry utility that just works.
1npm install nice-retry
1import {retry} from 'nice-retry'; 2 3// Retry any async operation 4await retry.async(() => someAsyncOperation()); 5 6// Retry fetch requests 7await retry.fetch('https://api.example.com/data');
That's all you need for 90% of use cases! 🎉
1// Retry with custom attempts 2await retry.async(fn, {maxAttempts: 5}); 3 4// Retry with custom delay 5await retry.async(fn, {initialDelay: 1000}); 6 7// Retry fetch with options 8await retry.fetch('https://api.example.com/data', { 9 retry: {maxAttempts: 3}, 10});
1await retry.async(fn, { 2 retryIf: error => error.name === 'NetworkError', 3});
1await retry.async(fn, { 2 fallback: async () => backupOperation(), 3 // Or multiple fallbacks 4 fallback: [async () => primaryBackup(), async () => secondaryBackup()], 5});
Backoff is a technique that progressively increases the delay between retry attempts. This helps prevent overwhelming the system being called and allows it time to recover from any issues. Like gradually stepping back when something's not working, rather than continuously trying at the same rate.
1await retry.async(fn, { 2 backoffStrategy: 'exponential', // 1s → 2s → 4s (default) 3 backoffStrategy: 'linear', // 1s → 2s → 3s 4 backoffStrategy: 'aggressive', // 1s → 3s → 9s 5 backoffStrategy: 'fixed', // 1s → 1s → 1s 6});
Jitter adds randomness to retry delays to prevent multiple clients from retrying at exactly the same time. This is particularly important in distributed systems where synchronized retries could cause "thundering herd" problems - where many clients hit a service simultaneously after a failure.
1await retry.async(fn, { 2 jitterStrategy: 'full', // Random between 0 and delay (default) 3 jitterStrategy: 'equal', // Random between delay/2 and delay*1.5 4 jitterStrategy: 'decorrelated', // Independent random delays 5 jitterStrategy: 'none', // Exact delays 6});
1const controller = new AbortController(); 2 3await retry.async(fn, { 4 signal: controller.signal, 5}); 6 7// Cancel retries 8controller.abort();
1await retry.fetch('https://api.example.com/data', { 2 retry: { 3 retryStatusCodes: [408, 429, 500, 502, 503, 504], // HTTP status codes that will trigger a retry 4 retryNetworkErrors: true, // Whether to retry on network/connection errors 5 }, 6});
1function async<T>( 2 fn: () => Promise<T>, 3 options?: RetryAsyncOptions<T>, 4): Promise<RetryAsyncResult<T>>; 5 6interface RetryAsyncResult<T> { 7 data: T; // The result of the function 8 attempts: number; // The number of attempts made 9 totalTime: number; // The total time taken for all attempts 10 errors: Error[]; // The errors that occurred during the attempts 11}
1function fetch( 2 input: RequestInfo | URL, 3 init?: RequestInit & { 4 retry?: RetryFetchOptions; 5 }, 6): Promise<RetryFetchResult>; 7 8interface RetryFetchResult { 9 response: Response; // The response from the fetch request 10 attempts: number; // The number of attempts made 11 totalTime: number; // The total time taken for all attempts 12 errors: Error[]; // The errors that occurred during the attempts 13}
1import { 2 MaxRetriesExceededError, // Thrown when max retries are exceeded 3 RetryAbortedError, // Thrown when the operation is aborted 4 RetryConditionFailedError, // Thrown when the retry condition check fails 5 RetryOperationError, // Base error for all retry operations 6} from 'nice-retry';
Full TypeScript support with comprehensive type definitions:
1import type { 2 BackoffStrategy, 3 JitterStrategy, 4 RetryAsyncOptions, 5 RetryFetchOptions, 6} from 'nice-retry';
All options are optional with smart defaults:
1{ 2 maxAttempts: 3, 3 initialDelay: 1000, 4 maxDelay: 30000, 5 jitterStrategy: 'full', 6 backoffStrategy: 'exponential', 7 retryNetworkErrors: true, 8 retryStatusCodes: [408, 429, 500, 502, 503, 504] 9}
We welcome contributions! Check out our contributing guide.
MIT © Arshad Yaseen
No vulnerabilities found.
No security vulnerabilities found.