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

84
Views
Get URL response code and store it in variable using https.get

I'm simply using https.get to retrieve a URL response code, but I don't want to just show it in the console, I want to store it in array to later insert it in a DB table. Here's what I'm doing:

results.forEach((element, index) => {
 link[index] = element.AppURLAndroid;
 https.get(link[index], function(res) {
   resCode[index] = res.statusCode;
  }).on('error', function(e) {
  console.error(e);
  });                
});

As you can see, I'm retrieving the URLs from an array, getting the response code, and trying to store it in another array. The problem relies in this line resCode[index] = res.statusCode; .. if I do console.log it works fine and I can see the response code, but somehow I just can't assign it into a variable or array. I also tried using a global variable like global.resCodeTemp, but it also doesn't work. What am I doing wrong?

Thank you.

[EDIT] : there are no error thrown, I just try to print the array after the insertion and the array is empty.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Can you please try below code. In below code I have pass index in function to use in rescode.

results.forEach((element, index) => {
 link[index] = element.AppURLAndroid;
 https.get(link[index], function(res,index) {
   resCode[index] = res.statusCode;
  }).on('error', function(e) {
  console.error(e);
  });                
});
about 4 years ago · Juan Pablo Isaza Report
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!