title: How to return Response body urllib node js
body: <p>return result.res.data don't return the resp body outside of request func.
  am trying to wrap this in a function and be able to call it wth ext_id and domain_name as args and get  the response body in return.</p>
  <p>btw am new to js.</p>
  <pre class="lang-js prettyprint-override"><code>var urllib = require('urllib');
  
  ext_id = 1;
  domain_name = &quot;map&quot;;
  var api_cookie = &quot;PHPSESSID=55700000;&quot;
  var api_bodyString = &quot;action=checks_domaines&amp;ext=&quot;+ ext_id +&quot;&amp;dom=&quot;+ domain_name;
  
  headers  =  {
      &quot;Content-Length&quot;: api_bodyString.length
  }
  
    
  urllib.request('https://www.example.com:443/en/api/ch.php', {
      method: 'POST',
      headers: headers,
      content: api_bodyString
    }).then(function (result) {
      if(result.res.statusCode == 200){
          return result.res.data;
         // console.log('status: %s, body size: %d, headers: %j', result.res.statusCode, result.data.length, result.res.headers);
         // console.log('resp: %s',  );
      }}).catch(function (err) {
      console.error(err);;
  })
  
  // it returns an error : result.res.data is not defined 
  //console.log(result.res.data)
  
  
    
  </code></pre>