Monday 15 July 2019

Http echo service written in Node.js

I have added a small repo on Github that shows how to create a simple HTTP echo service. https://github.com/toreaurstadboss/NodeJsHttpEchoServer The server.js is script is this:
let http = require('http');

console.log('Attempting to start the Node.js echos server on port 8081..')
http.createServer().on('request', function(request, response){
 request.pipe(response);
}).on('close', function(){
    console.log('The Node.js echo server has been closed.')
})
.listen(8081);

console.log('Node.js echo server started on port 8081.')

This will pipe out the requesting data to the response. Test it out with this command for example in a command window: curl -d "Hello dog" http://localhost:8081 Note - use not Powershell for this command as Powershell has aliased curl command for Invoke-WebRequest. Rather install curl with Chocolatey for example, choco install curl
Share this article on LinkedIn.

3 comments:

  1. Nice Article Thank you..

    ELearn Infotech offers Real-time Node JS Training in Hyderabad. Our Node JS course includes from Basic to Advanced Level Node JS Concepts. We have designed our Node JS course content based on students Requirement to Achieve Goal. We offer both Node JS class room training in Hyderabad and Node JS Course online training by 10+ years Realtime Experts.

    ReplyDelete