0

I want to get a response from node js API to client-side on every step the API completes till API completes its full step.

Suppose I call localhost/api/doStepCompleate on my backend(Node js) API will complete multiple steps but want to send every step response to the client-side till the API completes its full task.

Thank you

Abul Hasan
  • 53
  • 10

1 Answers1

0

If this is an http request/response, then you can use res.write() on the server to send partial responses and finally call res.end() when you're done.

A challenge here will be that many clients are not set up to process partial responses. Libraries such as fetch() will wait for the entire response and not notify their caller of partial responses unless you configure the response as a stream and you have client-side code to parse arbitrary chunks of data as it arrives. See here for some idea how that can work.

jfriend00
  • 683,504
  • 96
  • 985
  • 979