So essentially I am using the node-url-shortener library to shorten a link, however, after using that function I want to pass the new shortened link (shortenedUrl) outside of the function and then log it in the console.
If I throw the console.log inside the function it logs perfectly fine but obviously that is not what I'm trying to achieve here...
This was my attempt at doing so:
const shortUrl = require('node-url-shortener');
var shortenedUrl;
shortUrl.short('www.google.com', function(err, shortUrl){
shortenedUrl = shortUrl;
// do somemthing here to pass the shortenedUrl outside the function
});
console.log(shortenedUrl);
Any help is appreciated and thanks in advance!