Monday, 17 April 2017

NodeJS Variable Collision?

Issue : Data INFO_X sometimes and randomly become Null.

Question ,

1)Does the variable overwrites each other for INFO_1 INFO_2 INFO_3 since Nodejs run fast unlike PHP it follows a sequence/step by step.

I checked for NULLS before doing a request but the debug shows it's NOT NULL before executing the 2nd request, at random, random variables will become null upon submitting the 2nd request.

I also checked my source is definitely not returning any null.

Is the variable being overwritten before the 2nd request is sent or what? Please advice.

var request = require('request');

var urls = [ 'URL',
             'URL',
             'URL'];

urls.forEach(processUrl);

function processUrl(url) {

  request(url, function (error, response, body) {
  if (!error) {
    var obj = JSON.parse(body);
     for (var i = 0, len = obj['products'].length; i < len; ++i) {
         var data = obj['products'][i];
         var INFO_1 = data.INFO_1
         var INFO_2 = data.INFO_2
         var INFO_3 = data.INFO_3

        request("URL/POSTINFO?INFO_1="+INFO_1+"&INFO_2="+INFO_2+"&INFO_3="+INFO_3+"&seller_id=", function(error, response, body) {
            console.log(body);
        });

     }
  }
});

}



via CodeGuru

No comments:

Post a Comment