I’m new to Node.js but I wanted to use it as a quick web server which would simply take in a request uri and then run a query on an internal service which returns a JSON stream.
I.e. something like this:
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname;
if(uri === "/streamA") {
//send get request to internal network server http://server:1234/db?someReqA -->Returns JSON ....?
//send response to requestor of the JSON from the above get ....?
}
else if(uri === "/streamB") {
//send get request to internal network server http://server:1234/db?someReqB -->Returns JSON ....?
//send response to requestor of the JSON from the above get....?
}.listen(8080);
I’m using the newest stable version of node.js – version 0.4.12. I was hoping this would be very easy to do however, I havent been able to find some examples on the net as they all seem to use an old API version so I’m getting error after error.
Would anyone be able to provide a code solution to the above that works with the new Node APIs?
Thanks!
here is a code that should explain your task: