title: Node js wait for request.get callback happens and then go to next line
body: <p>I am trying to make one request to URL and then I am fetching image data from that. Now what I need to do is:</p>
  
  <ol>
  <li>Get Image data from request</li>
  <li>Assign this data to one variable</li>
  <li>Now print this/ push this data</li>
  </ol>
  
  <p>What I am doing ?</p>
  
  <pre><code>var data;
  request.get(URL, function (error, response, body) { //1
          if (!error &amp;&amp; response.statusCode == 200) {
              data = "data:" 
              + response.headers["content-type"]
              + ";base64,"
              + new Buffer(body).toString('base64');
          }
      });
  console.log(data) //2
  </code></pre>
  
  <p>Problem ?</p>
  
  <p>Now I need request to happen at first and then move to console.log so that my data will be not undefined and then later I can push it in my dictionary. But right now it makes one request from 1 and then it moves to 2 which is console.log and then it gives error. So what I can do ?</p>
  
  <p>Note: I don't want to add console.log inside that function because I can't put all my code below request inside that function.</p>