http.get fails most of the time while file_get_contents doesnt fail. What am I doing wrong with my node script?

I am using node to download data from overpass. I am constantly receiving errors (see far below), however, if I use file_get_contents in codeigniter I never receive any errors and data downloaded smoothly. I am wondering what am I doing wrong with my node script? I have even added more attempts to download and increased the timeout but no luck.

This is my node script:

const fs = require('fs');
const path = require('path');
const http = require('http');

// Overpass API URL and query
const overpassUrl = 'http://overpass-api.de/api/interpreter';
const query = '[out:xml][timeout:25];area(3600382313)->.searchArea;(nwr["landuse"="winter_sports"](area.searchArea););out geom;';

// Path for the temporary XML file
const xmlFilePath = path.join(__dirname, '../writable/ski/sknowed_calcs/aa_winter_sports_polygons.xml');

// Maximum number of retries
const maxRetries = 3;

// Function to fetch data
function fetchData(retries = 0) {
  console.log(`Fetching data from Overpass API... (Attempt ${retries + 1}/${maxRetries})`);

  // Encode query for URL
  const url = `${overpassUrl}?data=${encodeURIComponent(query)}`;

  // Send HTTP GET request with increased timeout
  http.get(url, { timeout: 220000 }, (res) => {
    res.setEncoding('utf8'); // Ensure response is treated as UTF-8

    if (res.statusCode !== 200) {
      console.error(`Failed to fetch data: ${res.statusCode} ${res.statusMessage}`);
      res.resume(); // Consume response to free up memory
      return;
    }

    let xmlData = '';

    // Collect data chunks
    res.on('data', (chunk) => {
      xmlData += chunk;
    });

    // When the entire response is received
    res.on('end', () => {
      console.log('Data fetched successfully.');

      // Ensure directory exists
      fs.mkdirSync(path.dirname(xmlFilePath), { recursive: true });

      // Save the XML response to a file with UTF-8 encoding
      fs.writeFileSync(xmlFilePath, xmlData, 'utf8');
      console.log(`XML file saved at ${xmlFilePath}`);
    });
  }).on('error', (error) => {
    if (error.code === 'ETIMEDOUT' && retries < maxRetries - 1) {
      console.error(`Request timed out. Retrying... (${retries + 1}/${maxRetries})`);
      setTimeout(() => fetchData(retries + 1), 5000); // Retry after 5 seconds
    } else {
      console.error('Request failed:', error);
    }
  });
}

// Run the function
fetchData();

This is the error I am receiving:

Fetching data from Overpass API... (Attempt 1/3)
Fetching data from Overpass API... (Attempt 2/3)
Fetching data from Overpass API... (Attempt 3/3)

Request timed out. Retrying... (1/3)
Request timed out. Retrying... (2/3)
Request failed: AggregateError [ETIMEDOUT]: 
    at internalConnectMultiple (node:net:1139:18)
    at internalConnectMultiple (node:net:1215:5)
    at Timeout.internalConnectMultipleTimeout (node:net:1739:5)
    at listOnTimeout (node:internal/timers:616:11)
    at process.processTimers (node:internal/timers:549:7) {
  code: 'ETIMEDOUT',
  [errors]: [
    Error: connect ETIMEDOUT 162.55.144.139:80
        at createConnectionError (node:net:1675:14)
        at Timeout.internalConnectMultipleTimeout (node:net:1734:38)
        at listOnTimeout (node:internal/timers:616:11)
        at process.processTimers (node:internal/timers:549:7) {
      errno: -110,
      code: 'ETIMEDOUT',
      syscall: 'connect',
      address: '162.55.144.139',
      port: 80
    },
    Error: connect ENETUNREACH 2a01:4f8:261:3c4f::2:80 - Local (:::0)
        at internalConnectMultiple (node:net:1211:16)
        at Timeout.internalConnectMultipleTimeout (node:net:1739:5)
        at listOnTimeout (node:internal/timers:616:11)
        at process.processTimers (node:internal/timers:549:7) {
      errno: -101,
      code: 'ENETUNREACH',
      syscall: 'connect',
      address: '2a01:4f8:261:3c4f::2',
      port: 80
    },
    Error: connect ETIMEDOUT 65.109.112.52:80
        at createConnectionError (node:net:1675:14)
        at Timeout.internalConnectMultipleTimeout (node:net:1734:38)
        at listOnTimeout (node:internal/timers:616:11)
        at process.processTimers (node:internal/timers:549:7) {
      errno: -110,
      code: 'ETIMEDOUT',
      syscall: 'connect',
      address: '65.109.112.52',
      port: 80
    },
    Error: connect ENETUNREACH 2a01:4f9:3051:3e48::2:80 - Local (:::0)
        at internalConnectMultiple (node:net:1211:16)
        at Timeout.internalConnectMultipleTimeout (node:net:1739:5)
        at listOnTimeout (node:internal/timers:616:11)
        at process.processTimers (node:internal/timers:549:7) {
      errno: -101,
      code: 'ENETUNREACH',
      syscall: 'connect',
      address: '2a01:4f9:3051:3e48::2',
      port: 80
    }
  ]
}

And this is my codeigniter4 script that never fails:

    public function osm_get_aa_winter_sports_polygons(){
        
        helper('filesystem');
        $query_get_skiArea = urlencode('[out:xml][timeout:25];area(3600382313)->.searchArea;(nwr["landuse"="winter_sports"](area.searchArea););out geom;');
        $overpass = 'http://overpass-api.de/api/interpreter?data='.$query_get_skiArea;
        $html = file_get_contents($overpass);
        if (write_file(WRITEPATH. "/ski/osm_data/temp_aa_winter_sports_polygons.xml", $html)){
                if (file_exists(WRITEPATH.'/ski/osm_data/aa_winter_sports_polygons.geojson')) {
                    $fileD = "aa_winter_sports_polygons.geojson.".date('m-d-Y-H-i-s'); //A e
                    @rename(WRITEPATH.'ski/osm_data/aa_winter_sports_polygons.geojson', WRITEPATH.'ski/'.$fileD);
                }
                exec('osmtogeojson '.WRITEPATH.'/ski/osm_data/temp_aa_winter_sports_polygons.xml > '.WRITEPATH.'/ski/osm_data/aa_winter_sports_polygons.geojson');
                return redirect()->to('/admin/ski/osm_data')
                                 ->with('info', 'Success - aa_winter_sports_polygons data');
        } else {
            // dd($TaskResult);
            $error = "something happened Harry";
            return redirect()->back()
                             ->with('errors', $error)
                             ->with('warning', 'Invalid Data')
                             ->withInput();
        }
    }