-1

I'm trying to figure out how I can send multiple requests to let the client know that uploading and processing has finished.

For example: Let the client know that upload has finished, and processing has started. When processing has been finished, send another request to notify the client.

I only want to know the proper functions to use because it seems that sending two res.write()'s wont send until I call res.end()...

Owenimus
  • 21
  • 4

1 Answers1

2

You actually want to inform the client about updates that happen asynchronously on the server / in the backend.

From the top of my head, there are a few ways to achieve getting asynchronous information to the client:

  1. Open a stream and push updates via the stream to the client (for example, using server-sent-events)
  2. Open a websocket and push your messages to the client (you need to manage the HTTP and websocket connections to write to the correct one)
  3. Create a new route to let clients subscribe to information about the status of a job (some example code)

I'd select one of the solutions depending on your current client design. If you have something like websockets already available, I'd use that - but it's quite something to setup, if you don't. Streaming might not work cross-browser, but is quite easy to build. For the third option, you probably need more housekeeping in order to not create some memory leaks if a client disconnects.

Narigo
  • 2,979
  • 3
  • 20
  • 31