Registry / devops / nestjs-axios-retry

nestjs-axios-retry

JSON →
library1.0.7jsnpmunverified

A NestJS module (v1.0.7) that integrates axios-retry with NestJS's HttpModule, providing configurable retry logic for HTTP requests. It supports retry count, delay strategies (exponential backoff), custom retry conditions, and on-retry callbacks. Differentiates from manual axios-retry usage by offering a declarative NestJS module setup with forRoot configuration. Uses axios-retry v4 and requires @nestjs/common and @nestjs/core v10. Release cadence is low; last update 2023.

npm install nestjs-axios-retry
INSTALL
IMPORT
SIG · NESTJS-AXIOS-RETRY
N
nestjs-axios-retry
devopsjavascriptv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AxiosRetryModule
import { AxiosRetryModule } from 'nestjs-axios-retry'
const AxiosRetryModule = require('nestjs-axios-retry').AxiosRetryModule
ESM-only; use named import. CommonJS require may not work due to ESM packaging.
AxiosRetryModule (default import)
import AxiosRetryModule from 'nestjs-axios-retry'
import { default as AxiosRetryModule } from 'nestjs-axios-retry'
The package only exports a named AxiosRetryModule, no default export.
axiosRetry (from axios-retry)
import axiosRetry from 'axios-retry'
import { axiosRetry } from 'axios-retry'
axios-retry v4 is ESM-only; default export. CommonJS require('axios-retry').default may be needed in some setups.
HttpService
import { HttpService } from '@nestjs/axios'
import { HttpService } from 'nestjs-axios-retry'
HttpService is from @nestjs/axios, not from this package.

Registers AxiosRetryModule with exponential backoff, 3 retries, and a condition to retry on HTTP 429. Then uses HttpService in a service.

import { Module } from '@nestjs/common'; import { AxiosRetryModule } from 'nestjs-axios-retry'; import axiosRetry from 'axios-retry'; @Module({ imports: [ AxiosRetryModule.forRoot({ axiosRetryConfig: { retries: 3, retryDelay: axiosRetry.exponentialDelay, retryCondition: (error) => error.response?.status === 429, onRetry: (retryCount, error, requestConfig) => { console.log(`Retry #${retryCount}`); }, }, }), ], }) export class AppModule {} // In a service: import { Injectable } from '@nestjs/common'; import { HttpService } from '@nestjs/axios'; import { firstValueFrom } from 'rxjs'; @Injectable() export class AppService { constructor(private httpService: HttpService) {} async fetchData() { const response = await firstValueFrom( this.httpService.get('https://api.example.com/data') ); return response.data; } }
Debug
Known issues
gotchaAxiosRetryConfig is typed inline; importing from 'axios-retry' may lose typing if the version mismatches.
fix
Ensure axios-retry version is compatible (v4 recommended). If TypeScript errors, manually define config type.
affects: >=1.0.0
gotchaAxiosRetryModule.forRoot() must be called; calling forFeature() is not supported for per-module configuration.
fix
Use forRoot() only in root module. For feature modules, import the same forRoot configuration or use global module.
affects: >=1.0.0
gotchaThe module does not support per-request retry config via 'axios-retry' key in AxiosRequestConfig if axios-retry v3 or lower is used.
fix
Use axios-retry v4 (peer dependency). With v3, the config key is different ('retry' instead of 'axios-retry').
affects: >=1.0.0
deprecatedDeprecated: The package's peer dependency on @nestjs/common ^10.1.2 may not work with NestJS v9.
fix
Update to v1.0.7 or later, or manually check peer version compatibility.
affects: >=1.0.0 <1.0.7
breakingBreaking: v1.0.0 removed support for older axios-retry versions; only v4 is supported.
fix
Upgrade axios-retry to v4. See migration guide for axios-retry v4 changes.
affects: >=1.0.0
gotchaThe HttpService from @nestjs/axios returns Observables; forgetting to convert to Promise (firstValueFrom) will not run the request.
fix
Always use firstValueFrom() or lastValueFrom() to execute the HTTP call.
affects: >=1.0.0
gotchaPer-request 'axios-retry' config may override module-level config completely; not merge.
fix
Specify all needed retry options in per-request config; module-level defaults are ignored.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'nestjs-axios-retry' or its corresponding type declarations.
Package not installed or missing TypeScript type declarations.
fix
Run npm install nestjs-axios-retry axios-retry && ensure tsconfig.json includes node_modules types.
TypeError: axiosRetry.exponentialDelay is not a function
Using commonjs require('axios-retry') incorrectly; axios-retry v4 is ESM-only.
fix
Use import axiosRetry from 'axios-retry'. If using CommonJS, use const axiosRetry = require('axios-retry').default.
UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'status')
retryCondition expects error.response to exist, but error may be network error without response.
fix
Add null check: (error) => error.response?.status === 429.
Error: Nest can't resolve dependencies of the HttpService (*). Please make sure that the argument dependency at index [0] is available in the AppModule context.
AxiosRetryModule not imported or forRoot not called.
fix
Import AxiosRetryModule and add it to imports array with forRoot() call.
No overload matches this call. Type '{ 'axios-retry': { ... } }' is not assignable to type 'AxiosRequestConfig'.
TypeScript does not recognize the 'axios-retry' key in AxiosRequestConfig.
fix
Extend AxiosRequestConfig type with 'axios-retry' property, or cast to any: this.httpService.get(url, { 'axios-retry': {...} } as any)
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies
axios-retryrequiredPeer dependency for retry functionality
Agent activity
4 hits · last 30 days
node
4
Resources