Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda