Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run node.js with timeout?

Is possible to run node.js with timeout? In my script I am connecting to external services which sometimes don't respond. Then my script hangs and the node.js process hangs.

I would like to force exit process after 5 minutes no matter if there is an error, if the process hangs or if everything is being done correctly.

It is independent of the services I use. I just want to kill the script after 5 minutes in any situation.

like image 609
penono Avatar asked Mar 03 '26 15:03

penono


1 Answers

You want to set the server.timeout property (default 0 no timeout)

Example.

var server = app.listen(<port>, function() {
  debug('Express server listening on port ' + <port>);
});
server.timeout = 300000; //5 minutes
like image 70
xMayank Avatar answered Mar 06 '26 03:03

xMayank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!