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

132
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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