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.
I really like this article. Very informative topic
ReplyDeleteNode JS Online training
Node JS training in Hyderabad
Great post. keep sharing such a worthy information
ReplyDeleteSoftware Testing Training in Chennai
Software Testing Course in Bangalore
Software Testing Training in Coimbatore
Software Testing Course in Madurai
Best Software Testing Institute in Bangalore
Software Testing Training in Bangalore
Software Testing Training Institute in Bangalore
Tally Course in Bangalore