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

131
Visualizações
Why does my Echo Server not work on localhost?

I am trying to create an echo server with Node.js so it should read body of incoming requests and send that same body as the response. You can see below my code. Basically when I run it and on another terminal, I type curl --location --request POST 'localhost:3000' --header 'Content-Type: text/plain' --data-raw 'Test message' to test it, it prints the body inside the curl terminal and server terminal, but not on localhost.

const http = require('http');

http.createServer((request, response) => {

    
    let body = [];
    request.on('data', (chunk) => {
      body.push(chunk);
    }).on('end', () => {
      response.writeHead(200, { 'Content-Type': 'text/plain' });
      body = Buffer.concat(body).toString();

      response.write(JSON.stringify(body));
      console.log(JSON.stringify(body));
      response.end();
    });
}).listen(3000, 'localhost');
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

curl doesn't print the request body, it prints the response body the server is returning to you. In other words - this echo server works as planned.

about 4 years ago · Juan Pablo Isaza Relatório
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