I have a Jquery mobile client the sends an Ajax request to the Express server. From the Express server, it connects to the MongoDB using async function. the problem I face is the when the request is sent to MongoDB the responses delays few seconds. before receiving an empty JSON response sent to the client. how to handle the client-side request to wait until the response is received.
Any advice appreciated.
Thank you
Related
I had another quick question which I would also appreciate feedback on if possible.
My app has live data which I am using socket.io to pass from server to clients.
I use axios to send the initial request to the server when the user logs in. However, after that should I use the socket.io connection to do all other request to the server after that or still use axios for general requests to the server and the socket.io to just send the live data back and forth between clients?
I would like to send updates of a running HTTP request to the client to tell it at what stage the request-triggered process currently is.
The process behind the request does currently the following things (in this order):
Client-side:
Client sends an HTTP Request (upload of a file) to the server
Server-side:
Takes the uploaded file
Encrypt it
Upload it to an archive storage
Return response to the client
(Meanwhile, the client does not know what currently happens)
Client-side:
Get response and show it to the user
I want to tell the client at what stage the process is, like “Uploading done. Encrypting…” and so on.
Is there a way to realize that, or am I missing something? Is it even possible to do?
Frameworks I'm using:
Client: Next.js
Server: Hapi.dev for API development
Thanks
You can send non-final 1xx header responses for your http request as described here.
I have set up a express server with 2 endpoints. One of these endpoints never closes the http connection as it uses the http header 'transfer-encoding: chunked' and I am constantly using '''res.write''' to send data through this endpoint every few seconds.
On the client side however when I attempt to make a fetch request from this endpoint, the response doesn't show as it is waiting for the request to finish.
Would it be possible to actually receiving this changing data on the client side, instead of it waiting to complete the request?
Any help is greatly appreciated
I am working on a chat bot which uses node as its backend server. So, to respond back to user's query, I have to make some other api call which are taking long to respond which causes delay in providing response to the user.
My problem is whenever i call a third-party api from node server it's response time is around 500-900ms whereas Postman gives back the same response in 80-120ms.
I have tried using following modules, but all of them give almost same response time:
request
axios
https
How to achieve the same response time which i am getting in the Postman?
I have one question.
In my current application I am using express, and I and using Express.get and Express.post method multiple times because I have multiple pages.
So, I want to intercept each response before sending it to client to add some state in response object.
Is there any way in express.js by which I can intercept each response before sending it to client.