I had here entire story. But after rereading it. It seemed pointless. GG.
Shorthand question:
Having backend Node.js server, let’s say I want to send a HTTP(S) JSON request to Node.JS server, at 127.0.0.1:6789. How can it be done using JavaScript (incl. jQuery)?
If you’re talking about making requests in the browser either $.ajax or fetch will let you make requests to an API.
There are cross domain restrictions, so if the api is on a different server to the code running in the browser you’ll also need to look at the crossDomain option in jQuery and CORS on the server to allow them to talk to each other.
If you’re trying to make a request from the server to another server you can use Node’s http module.
Doesn’t server run on a socket instead of file? How can I send request called [getMyName] (with headers of course) towards 123.12.12.12:4567. I can’t really AJAX request it 123.12.12.12/things.php?query=getMyName. Because it’s Node.JS, not PHP back-end. The process of Node is running on a socket, and is not accessible per file.
Any link or snippet available?
Once again.
Not from server to server. Not from server to user. But when users browses my website, I want Node.js backend, not PHP back-end. I know how to program Node.js back-end, but I need to contact front-end JavaScript with back-end Node.JS, instead of front-end JavaScript with back-end PHP (AJAX).
Node.js is certainly capable of handling normal http requests and accepting query string params.
It seems I can’t explain what I’m asking. But okay, let’s say that’s the answer. Could you provide me a piece of JavaScript (V8 front-end on client-side) that could send request over there? And produce wanted response. Assuming 127.0.0.1:8080?
It sounds like you are talking about how to use Web Sockets to communicate with a server though, for that you’ll want to look at http://socket.io/
Yes. That sounds a lot like it, but I still can’t find a way to bind JavaScript browser front-end at communication with Node.JS server.