geting async YouTube title from get-youtube-title npm library

216 Views Asked by At

I need to get a title from YouTube video. How can I change a request from this library to be async? Actually this returns undefined

this is a vue.js app

async addNewVideoToLocalStorage() {
     let id = getIdFromURL(this.videosUrl[0].url);
     let title = await getYoutubeTitle(id, async (e, t) => await t);
}

https://www.npmjs.com/package/get-youtube-title

1

There are 1 best solutions below

2
CaptainJack On BEST ANSWER
data: () => ({
  title: "",
})
async get_title() {
      var getYoutubeTitle = require('get-youtube-title');
      let id = 'QR1jRM4XTyc';
      await getYoutubeTitle(id, (e, t) => {
        return this.title = t
      })
      console.log(this.title);
}

async , await cannot work in getYoutubeTitle

try this way