0

The following code logs [Object Promise] instead of a string which is a thing I don't want. I've tried to make them both async function yet that didn't work.

...
let URL = searchYouTube(arg)
console.log(URL)
...

searchYouTube function:

async function searchYouTube(args) {
  youtubes(args, function (err, r) {
    let video = r.videos
    let Fvideo = video[0]
    console.log(Fvideo.url)
    return String(Fvideo.url)

  })
}
  • use then and catch? to wait for promise to resolve – Shubham Srivastava Dec 01 '20 at 10:36
  • Just making them async doesn't do anything. The promise won't be resolved until you `await` it or chain a `.then((response) => { ... })` – nbokmans Dec 01 '20 at 10:36
  • `async` functions always return promises, but there's no point in that being an async function since you don't `await` anything inside it (and there's only one statement inside it so there's no point in awaiting anything anyway). Also `searchYouTube` has no `return` statement so that promise will always resolve as `undefined`. The `return` statement in the anonymous function you pass to `youtubes` doesn't have any meaning unless the `youtubes` function itself does something with the return value of the callback (which seems unlikely) – Quentin Dec 01 '20 at 10:38
  • youtubes is a function that works and returns a video URL from argument provided to it. I just can't feed the result into any other function. – Random Dude Dec 01 '20 at 10:41
  • `youtubes` does not appear to **return** anyway, certainly you aren't doing anything with any value it may return. Read the duplicates. The second one in particular. – Quentin Dec 01 '20 at 11:06

0 Answers0