You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
What is the default timeout of a req in express? #3330
The default for 6.x is 2 minutes. You can use server.setTimeout(msecs) to set a different default timeout on the server.
I hope this helps!
Reacted by Oluwaseun Omoyajowo, Haroon Khan, Francois Wouts, Andy Potanin, Yvann Boucher, Roberto Sanchez, 微笑, Telmo "Trooper", Wilson A. Hamilton D., Christian Vadalà and 25 more
@vitoravale It's almost a year I can't really remember what we did as the project didn't work out. But I think it has to do with the azure storage module I used not giving the progress status of the blob while uploading, I filed the issue there.
Reacted by Oluwaseun Omoyajowo, Vitor A. Vale, Richard Dunn, Dendiom, Michael DePetrillo, Anjana Ganesan, Sebastian Kupke, Ahmet Cetin, Adrian Mora, Michael FIG and 97 more
Reacted by subchan yayan bachtiar, Loreto Parisi, Jonathan, Justyna Janczyszyn, Thomas Aumaitre, Jorge Mendoza, parampreet-smartdata, Cristian Cortez, Shir Brass, pj and 30 more
constapiTimeout=10*1000;app.use((req,res,next)=>{// Set the timeout for all HTTP requestsreq.setTimeout(apiTimeout,()=>{leterr=newError('Request Timeout');err.status=408;next(err);});// Set the server response timeout for all HTTP requestsres.setTimeout(apiTimeout,()=>{leterr=newError('Service Unavailable');err.status=503;next(err);});next();});
constapiTimeout=10*1000;app.use((req,res,next)=>{// Set the timeout for all HTTP requestsreq.setTimeout(apiTimeout,()=>{leterr=newError('Request Timeout');err.status=408;next(err);});// Set the server response timeout for all HTTP requestsres.setTimeout(apiTimeout,()=>{leterr=newError('Service Unavailable');err.status=503;next(err);});});
There should be a next() call in the end of the middleware.
Activity
dougwilson commentedon Jun 8, 2017
Hi @flickz by default, Express sits on top of the built-in Node.js HTTP server.
You can find the documentation on the timeout in the Node.js documentation: https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_settimeout_msecs_callback
The default for 6.x is 2 minutes. You can use
server.setTimeout(msecs)to set a different default timeout on the server.I hope this helps!
flickz commentedon Jun 9, 2017
@dougwilson Thanks
vitoravale commentedon Mar 22, 2018
@flickz did you solve the problem?
flickz commentedon Mar 22, 2018
@vitoravale It's almost a year I can't really remember what we did as the project didn't work out. But I think it has to do with the azure storage module I used not giving the progress status of the blob while uploading, I filed the issue there.
ktrzeciaknubisa commentedon May 18, 2018
@flickz @vitoravale I've found two ways to make it work.
You may set the timeout either globally for entire server:
or just for specific route:
IMHO the second sounds much proper :)
xerosanyam commentedon Sep 23, 2019
is there a way to know that the server closed because of timeout?
xerosanyam commentedon Sep 25, 2019
@ktrzeciaknubisa
for some reason, the second way is not working for me
req.setTimeout(500000);xerosanyam commentedon Sep 25, 2019
Figured it out, it was a typo 😓
It should be res, instead of req
ParkerOu commentedon Oct 3, 2019
Here's my solution:
luokuning commentedon Oct 16, 2019
There should be a
next()call in the end of the middleware.ParkerOu commentedon Oct 16, 2019
Thanks! I putted
next()in auth.