title: Javascript function returned an undefined value in NodeJs (Express)
body: <p>I am writing a nodejs function that download a video from youtube. The function should return whether or not the video was downloaded. The code below should print <em>Invalid Link</em> but instead I get <em>undefined</em>. I am new to NodeJs and Js. Please Help.</p>
  
  <pre><code>var youtubedl = require('youtube-dl');
  var fs = require('fs');
  
  var videoName="";
  var results="";
  
  function getVideo(videoLink) {
  
      var video = youtubedl(videoLink);
  
      video.on('error',function (err) {
      //console.log(err.message);
      results = "Invalid Link"
      });
  
      video.on('info', function (info) {
          console.log('Download started');
          //console.log('Title: ' + info.title);
          //console.log('Description: ' + info.description);
          //console.log('size: ' + info.size);
          videoName = info.title;
      });
  
      video.on('end', function () {
          //console.log("Finished Downloading Video");
          results = "Finished Downloading Video";
      });
  
      video.pipe(fs.createWriteStream('youtubeVideo.mp4'));
      return results;
  };
  
  console.log(getVideo("Some Invalid Link"));
  
  module.exports.getVideo = getVideo;
  </code></pre>