geeky_monster geeky_monster - 5 months ago 37
Node.js Question

Do NodeJS functions timeout if it takes too long ?

I have some third party APIs which run functions that take around 30 minutes to return results (they do some lengthy calculations ).
Now if I use Nodejs to call such an API with an appropriate callback, will Nodejs by default wait for the 30 minutes for the function to return the result or will it timeout ?
If it timesout, is there a way to increase the waiting time ?

Answer Source

The default of Linux could use anything between 20s - 120s as timeout

Depending on which request library you are using, you may have different syntax on setting the timeout. I personally like request a lot, Reference here

request.get('', {timeout: 1500}, function(err) {
    console.log(err.code === 'ETIMEDOUT');
    // Set to `true` if the timeout was a connection timeout, `false` or
    // `undefined` otherwise.
    console.log(err.connect === true);

I don't think NodeJS function itself would timeout though.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download