title: How to store JSON response in variable in Node.js?
body: <p>I am struggling to get response from API and save it in variable to use it further in Node.js. Maybe I don't know how the language works. Here is the problem:</p>
  
  <pre><code>// Objective, get current temperature of New Delhi in celcius
  
  var request = require('request');
  
  var url = "http://api.openweathermap.org/data/2.5/weather?id=1261481&amp;appid=#####&amp;units=metric";
  
  request(url, function (error, response, body) {
    if (!error &amp;&amp; response.statusCode == 200) {
      curTemp = JSON.parse(body).main.temp;  // curTemp holds the value we want
    }
  })
  
  // but I want to use it here
  console.log(curTemp);
  </code></pre>
  
  <p>I want to store JSON response from openweathermap (i.e. <code>body.main.temp</code>) to a variable. Then I'll be composing a tweet out of current temperature.</p>