Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda