NodeJS. I have a function named 'createDynamicLink' and I want this function to return the response body that returned in request object.
function createDynamicLink(){
.
.
.
.
request({
url: dynamicLinksApi,
method: "POST",
json: true,
body: body,
}, function (error, response, body) {
console.log("link: " + response.body.shortLink);
return response.body.shortLink; // <---- I want this value be // returned when I call the createDynamicLink function
});
}
var dynamicLink = createDynamicLink();
console.log(dynamicLink) // <----- This writes 'undefined' to // console screen
Thanks in advance.