Skip to content

How can I increase the headersTimeout with Node.js's fetch? #1989

Answered by metcoder95
ImRodry asked this question in Q&A
Discussion options

You must be logged in to vote

Sadly we cannot help you that much without a
Minimum Reproducible Example.

On a big overview, you cannot do that with fetch, as the spec does not support that configuration. One thing you can do, if wanting to use fetch in Node, is to pass a custom dispatcher that has all the timeout settings configured already.

e.g.

import { fetch, Agent } from 'undici'

const res = await fetch('https://example.com', {
  // Mocks are also supported
  dispatcher: new Agent({
    keepAliveTimeout: 10,
    keepAliveMaxTimeout: 10
  })
})
const json = await res.json()
console.log(json)

Reference - https://undici.nodejs.org/#/?id=undicifetchinput-init-promise

Replies: 1 comment 8 replies

Comment options

mcollina
Mar 5, 2023
Maintainer Sponsor

You must be logged in to vote
8 replies
@ImRodry
Comment options

@metcoder95
Comment options

@ImRodry
Comment options

@metcoder95
Comment options

Answer selected by ImRodry
@ImRodry
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants