The problem
I am making a music player for friends. One person is the host, only they play the music, and others just paste a youtube link, and then it gets sent through a node.js server.I am using embeded youtube videos to play the music. I am getting the youtube video id from the links, and just adding them onto the embed link.
I want to make a playlist feature, so that people can see what videos are next. I have multiple youtube ids, so getting the titles should be easy as that, because tools were already made for this scenario.
These tools are pretty simple: you have the youtube id, and maybe you need a youtube api key aswell, but then you can console.log() the data.
But when I want to display the data other than logging it onto the console, it just breaks. The application won't wait until the gather ends. It just returns undefined.
I've tried server-side, and client-side versions too, both failed. Javascript never waits.And I don't want to use php, i want to stay js/nodejs/jquerry.
What I've tried
Node.js
The get-youtube-title npm package;When using your own api-key, it gets the titles accurately. What I've learned when researching for this, is that Node.js is asynchronous (this is my first node.js project, don't judge me), so it kind of makes sence.I've tried a couple more packages, but those also failed.I don't know if this is relevant or not, but I'm using socket.io to send information between server and clients. I don't think it should be, but just putting it out there never failed.
Jquery
That is when I've switched to the client, and I've tried this answer on stackoverflow, and same issue.Even tough javascript should be single-threaded, so it should wait, right?
I am using google's cdn.I don't really want to use jquery, but if only this version works, jquery answers are appreciated.
Conclusion
Console.log()-ing always works! It always waits until the data is collected!I just want to change a div's innerText, and it returns undefined.