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

130
Views
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 answers
Answer question

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 Report
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!