DEV Community

loading...

Discussion on: Node.js send JSON to local client

Collapse
rhymes profile image
rhymes • Edited

Hi Liz, you have a jQuery client that calls the server through AJAX, so you decide a route, let's say GET /dataFromApiServer and in that function you issue the request to such API server, parse the JSON data and then "send it to the client" as a JSON response, so that jQuery can log it in your success.

How do you send it to the client? You can use expressjs.com/en/4x/api.html#res.json

So the flow is:

  • client jQuery calls the node server
  • the node server calls the API and waits for the response
  • the response from the API is sent as a JSON response to jQuery
Collapse
binarydigit profile image
Liz Rodriguez Author

Thanks for your reply! So it's a workflow issue, I think I understand now... I'll give this a try and update with my progress!

Collapse
binarydigit profile image
Liz Rodriguez Author

Annnnnd I have success! I realized I needed to do exactly what rhymes said and re-do my routing. I started my request on the client, then did the api call on the node server, and it responded. (I ended up using res.send(body) in my request function.)

Thanks for your help!!

Collapse
rhymes profile image
rhymes

no worries, glad it worked!