0

I am using node-fetch to perform a get request

const fetch = require("node-fetch");

   try {
      const response = await fetch(
        `https://someurl/?id=${id}`
      );
    } catch (error) {
      console.error(error);
    }

The API take long time to return the response, around 15 minutes. With postman everything works fine, but with node-fetch I get a time out error after 600000 ms. So I assume node-fetch has a default timeout. I found some ways to change the default time-out, but if I understand the code well, this will make the default timeout shorter, but will not extend it. Any advice on that?

import * as fetch from "node-fetch"

export default function (url: any, options: any, timeout = 5000) {
  return Promise.race([
    fetch(url, options),
    new Promise((_, reject) => setTimeout(() => reject("timeout"), timeout)),
  ])
}
user567
  • 3,712
  • 9
  • 47
  • 80

0 Answers0