geeky_monster geeky_monster - 20 days ago 7
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 http://www.sekuda.com/overriding_the_default_linux_kernel_20_second_tcp_socket_connect_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 https://github.com/request/request.

request.get('http://10.255.255.1', {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);
    process.exit(0);
});

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