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.