title: node.js - How do I get a variable out of request(url, function (error, response, body) { var getME})?
body: <p>the code I am using without params / filling: 
  <a href="https://www.npmjs.com/package/request" rel="nofollow noreferrer">https://www.npmjs.com/package/request</a></p>
  
  <pre><code>    var request = require('request');
      request('http://www.google.com', function (error, response, body) {
          console.log('error:', error); // Print the error if one occurred
          console.log('statusCode:', response &amp;&amp; response.statusCode); 
          // Print the response status code if a response was received
          console.log('body:', body); // Print the HTML for the Google homepage.
      });
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>    const YTAPIVideoURL = ('https://www.googleapis.com/youtube/v3/search?part=snippet&amp;channelId=' + Channel_ID + '&amp;eventType=live&amp;type=video&amp;key=' + YT_API_KEY);
  
      const YTAPIStatusURL = ('https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2Cstatus&amp;mine=true&amp;broadcastStatus=active&amp;key='+YT_API_KEY);
  
  
      var livestreamStatus = true;
      if (livestreamStatus == true) {
          var VIDEO_ID = "";
          var VIDEO_TITLE = "";
  
      // request options
          const APIoptions = {
              url: YTAPIVideoURL,
              method: "GET",
              timeout: 10000,
              followRedirect: true,
              maxRedirects: 10
          };
  
       //Request
          const APIrequest = request(APIoptions,
          function(error, response, body) {
              if (!error &amp;&amp; response.statusCode == 200) {
                  var jsonContent = JSON.parse(body);
                  console.log("jsonContent: " + jsonContent);
                  console.log("parsed info: " + jsonContent["items"][0]["id"]["videoId"]);
                  if ((jsonContent["items"][0]) != [""]) {
                      VIDEO_TITLE = jsonContent["items"][0]["snippet"]["title"];
                      VIDEO_ID = jsonContent["items"][0]["id"]["videoId"];
  
                      console.log(VIDEO_ID) //THIS IS THE DATA I NEED
  
                  } else {
                      videoId = false;
                      VIDEO_TITLE = false;
                  }
                  /*console.log(videoId);*/
              } else {
                  console.log('error' + response.statusCode);
              }
          });
          console.log(VIDEO_ID); //THIS IS WHERE I NEED THE DATA
  </code></pre>
  
  <p>I need to retrieve the VIDEO_ID from inside the require function... I've searched and am having a lot of trouble as all the solutions out there are just satisfied with using <code>console.log()</code> to print out the data from inside the require object|module.. </p>
  
  <p>The data that I want is grabbed and put in the var VIDEO_ID and displayed as it should on the lines;
  <code>console.log("parsed info: " + jsonContent["items"][0]["id"]</code>
  and 
  <code>console.log(VIDEO_ID) //THIS IS THE DATA I NEED</code> 
  Those lines log the data I need as it should.</p>
  
  <p>I need to have VIDEO_ID accessible from outside the function here: <code>console.log(VIDEO_ID); //THIS IS WHERE I NEED THE DATA</code>
  I know there are functions like <code>require.XXXX(APIoptions, callback)</code> but I have no idea what the callback is, and which one I should use.. help pls?</p>