Friday 14 April 2017

Nested HTTP Error on get request with Node.js

I'm having a problem, and I feel out of my depth when it comes to troubleshooting these problems.

One, my understanding of Node is very new/immature, and two my understanding of http isn't the strongest.

So here it goes out to the community for some hopeful help.

I've vetted my code, by first abstracting it's intent by using statically typed arrays of objects, and run it browser side to ensure all was working as expected (lacking the http.get request).

I've moved the same code over to the Node server side and have run it successfully with the same abstract data-set that I used locally, and all worked fine (Primary PORT 3030 Instance).

I then proceeded to introduce a http.get which is a little more complicated in more than one way.

Explanation:

Everything that I am doing is happening on my local machine for testing/non-production status development.

MyServerSetup

This being the case, I am ultimately performing an http.get request from my local machine on port 3030 and calling out to another instance of node (running on a separate instance of cmd.exe) listening on port 3000.

I've tested 3000 with the browser on its own, and it is working as expected:

I fire up chrome, goto http://:3000/bend/1, and it returns what I have set it up for (it runs a SQL select statement on the last value provided in the URL, and returns a JSON.stringify(obj) back to the browser -- See Image Below).

Proof_Of_3000_Working

Then I point my browser to http://:3030 and get:

Server Started on Port 3030...
TypeError: listener must be a function
    at TypeError (native)
    at ClientRequest.once (events.js:190:11)
    at new ClientRequest (_http_client.js:93:10)
    at Object.exports.request (http.js:49:10)
    at Object.exports.get (http.js:53:21)
    at getBendAndTypeByBend (<<MyPort3030Root>>\program.js:26:9)
    at p_processBends (<<MyPort3030Root>>\program.js:58:14)
    at doAll (<<MyPort3030Root>>\program.js:74:3)
    at <<MyPort3030Root>>\program.js:82:2
    at Layer.handle [as handle_request] (<<MyPort3030Root>>\node_modules\express\lib\router\layer.js:95:5)

I will be glad to show the code, but I'm not sure which section is really needed to troubleshoot the issue, as when there is not an HTTP.GET request, then each of these run fine in their own right.

I just don't know which way is which right now, and I'm hoping that someone here can help me understand where to begin understanding the problem, but ultimately how to solve it as well.

I know that this may be asking a lot, but I really feel stuck on this one because things seem to be working until I hook them together.



via Rick Riggs

No comments:

Post a Comment