Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!