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

129
Views
Is it possible to make the HTTP.Request response turn into a string variable?? (Node.js)(Newbie)

i'm using Node.js and this my source code...

const request = http.request(options, (response)=>{
   let chunks_of_data = [];
            
   response.on('data', (fragments) => {
        chunks_of_data.push(fragments);
   });
            
   response.on('end', () => {
        let response_body = Buffer.concat(chunks_of_data);  
        let final = response_body.toString();
        console.log(final);
   });

   response.on('error', (error) => {
        console.log(error);
   });
});

request.on('error', (error) => {
   console.log('Error Code: ' + error.code);
   console.log('Error Message: ' + error.message);
});

console.log(request.final);

The code is working and I received the right response from the other side of the server but is it possible to make the response turn into a string variable outside the http.request, the

console.log(request.final);

in the end of my code is not working. Can anyone help me?

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!