0

I have a promise call which takes a long time to return. So I need to send some response like "In progress" until the response is returned. Once it is returned , I need to send another response saying "Done".

I want this in Nodejs-Express App

How to do it?

  • 1
    You can only respond once to a given request. Typically you'd return "accepted" and give a location to poll for updates. – jonrsharpe Apr 11 '22 at 19:28
  • 1
    While [technically](https://stackoverflow.com/a/16909228/1048572) [possible](https://stackoverflow.com/q/1806228/1048572), it's rather unusual. You'd use something like [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) instead. – Bergi Apr 11 '22 at 19:32

1 Answers1

1

Using SocketIO would be an option as you would maintain a stream of data open while it is required. But you go beyond of a simple http Express server ...

Wax
  • 110
  • 6