Skip to main content

Install the package

Resilience is available on npm and can be installed using any package manager:
npm install @oldwhisper/resilience

Requirements

  • Node.js: 16.x or higher
  • TypeScript: 5.x or higher (optional, but recommended)
Resilience is an ESM-only package. Make sure your project is configured to use ES modules.

TypeScript setup

Resilience is written in TypeScript and includes type definitions out of the box. No additional setup is required. The library exports all type definitions you need:
import type { 
  ResilienceConfig,
  BackoffStrategy,
  CircuitBreakerConfig,
  ResilienceHooks 
} from '@oldwhisper/resilience';

Type definitions included

Resilience provides full TypeScript support with these key types:
  • ResilienceConfig - Configuration options for withResilience
  • BackoffStrategy - Fixed or exponential backoff configuration
  • CircuitBreakerConfig - Circuit breaker threshold and timeout settings
  • ResilienceHooks - Lifecycle hooks for observability
  • CircuitState - Circuit breaker state (CLOSED, OPEN, HALF_OPEN)

ESM configuration

Since Resilience is an ESM package, ensure your package.json includes:
{
  "type": "module"
}
If you’re using TypeScript, your tsconfig.json should have:
{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Verify installation

Create a simple test file to verify everything is working:
import { withResilience } from '@oldwhisper/resilience';

const greet = withResilience(
  (name: string) => `Hello, ${name}!`,
  { 
    name: 'greet',
    retries: 1 
  }
);

const result = await greet('World');
console.log(result); // "Hello, World!"
Run the test:
node test.js
If you see “Hello, World!” printed, your installation is successful!

Bundle size

Resilience is lightweight and has zero dependencies:
  • Uncompressed: ~8 KB
  • Minified: ~3 KB
  • Gzipped: ~1.5 KB
This makes it perfect for:
  • Browser applications
  • Serverless functions (AWS Lambda, Cloudflare Workers, etc.)
  • Edge computing environments
  • Microservices where bundle size matters

Environment support

Resilience works in any JavaScript environment that supports:
  • Promises and async/await
  • setTimeout and Date.now()
  • AbortController and AbortSignal (optional, for timeout cancellation)
Resilience uses AbortController for timeout cancellation when useAbortSignal is enabled. This feature requires an environment that supports the AbortController API (Node.js 15+, all modern browsers).

Next steps

Quickstart

Get started with your first resilient function

Core concepts

Learn about retries, backoff, and circuit breakers

Build docs developers (and LLMs) love