0

I'm trying to return response value and use it. But my callback function doesn't work properly. Please review the code and help me. I tried so many things. I read articles, stackoverflow questions/answers about callback functions. None of 'em work in my situation. If you know how can I solve it, please help me, Thanks in advance

function createDynamicLink(callback){
   .
   .
   .
   .

  request({
    url: dynamicLinksApi,
    method: "POST",
    json: true,
    body: body,
  }, function (error, response, body) {
    callback(response.body.shortLink);
  });
}

var dynamicLink = createDynamicLink(function (returnValue){
  console.log(returnValue) // <----- this works
  return returnValue; // I return it so the returnValue assign 'dynamicLink' variable 
}); 
console.log(dynamicLink)  // <----- But it won't assign. it says 'undefined'

0 Answers0