Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
How to return Response body urllib node js

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.

btw am new to js.

var urllib = require('urllib');

ext_id = 1;
domain_name = "map";
var api_cookie = "PHPSESSID=55700000;"
var api_bodyString = "action=checks_domaines&ext="+ ext_id +"&dom="+ domain_name;

headers  =  {
    "Content-Length": 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)


  
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!