因此,基本上,我正在使用 node-url-shortener 库来缩短链接,但是,在使用该函数之后,我想将新的缩短的链接(shortenedUrl)传递给函数之外,然后将其记录在控制台中。
如果我将console.log放在函数中,它的日志记录就很好了,但是显然那不是我要在这里实现的目标...
这是我这样做的尝试:
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);
感谢您的任何帮助,并在此先感谢您!