[Solved] Massive data & Node.js – increasing timeout for request of REST API functions

In case of operations for big data regarding fetching numerous records, operations taking a bit time (e.g. > 3-5 minutes)  or uploading a blob on azure local storage even if we using async operations   node.js in this situations can close or reject current request due to exceed default timeout of request. In this situation we have following below presented two possible solutions. I prefer second solution for specific route – because we are focusing only on critical sections in our server. Increasing timeout for whole when we have a planty different rest api functions not always is a good idea. All of presenting below solutions using setTimeout(miliseconds) function.

We may set the timeout either globally for entire server:

var server = app.listen();
server.setTimeout(500000);

or just for specific route:

app.post('/xxx', function (req, res) {
   req.setTimeout(500000);
});
April 8th, 2020