I'm very green to node.js, I understand due to the asynchronus nature of callbacks the call back will not be returned before the variables str gets set.
I noticed that line 165 prints outs successfully, but 171 fails for the aforementioned reasons.
I've read several posts, but having trouble understanding how to re-write my code so the variable str contains the contents of the console.log in line 165. I tried experimenting with .binds{str:str}, but no luck. How do I obtain the contents of str outside the scope of the callback once its done?
154 var str;
155 var  callBack  = function(response) {
156 var str = '';
157
158  //another chunk of data has been recieved, so append it to `str`
159   response.on('data', function (chunk) {
160    str += chunk;
161   } );
162
163  //the whole response has been recieved, so we just print it out here
164  response.on('end', function () {
165  console.log("******************"+str+"*********************");
166   });                        
167 };  
168                       
169   http.request(url, callBack).end();                            
170   console.log(str);                              
171   console.log("outside of callback---------------------xxx"+str+"xxx-----------------------------");
