Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
How can I save a variable inside Node Js Request

I would like to know how can I save globally a variable inside the request? In this case, I am doing multiple requests and I increment every time. I want to use increment variable, outside the request code.

The code is bellow:

        for(i = 0; i <= querries.startDates.length - 2; i++)
        {
            var increment;
                //console.log(querries.endDates[i]);
                
                url = `https://api.weatherbit.io/v2.0/history/daily?city=${city}&start_date=${querries.startDates[i]}&end_date=${querries.endDates[i]}&key=${historicalApiKey}`;
                // console.log(url);
                request(url, function(err, response, body) 
                {
                            
                    // On return, check the json data fetched

                    if (err) 
                    {
                        res.render('HistoricalData', { weather: null, error: 'Error, please try again' });
                    } 

                    else 
                    {
                        //console.log(body)
                        let weather = JSON.parse(body);

                        //console.log(weather);

            
                        if (weather == undefined) 
                        {
                            //console.log("ana");
                            res.render('HistoricalData', { weather: null, error: 'Error, please try again' });
                        } 
                        else
                        {
                          
                           
                           
                           var weeklyInfo = structureData(loopThroughDays(weather),organizedTemperaturesMap);
                           //console.log(weeklyInfo.get('Oct'));
                           
                           

                           increment++;
                           
                        }
                
                    }

                    
                });  

            console.log(increment);
   
        }
        ```

In this case, increment will be 0. How can I actually do it? Thank you
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda