npm urllib ResponseTimeoutError - how to increase timeout?
02:15 04 Nov 2016

I am trying to use urllib to go to many different URLs to get some HTML and parse it. I have a loop that should go through about 5000 iterations with urllib:

urllib.request('a url here', options=[timeout=50000]).then(function (result) {
                // data is Buffer instance
                var $ = cheerio.load(result.data);
                $('dt').each(function () {
                    var news_html = cheerio.load($(this).html());
                    if (news_html('span.timestamp').html() != null) {
                        var date = news_html('span.timestamp').html();
                        var description = news_html('.story_title').html();
                        var link = news_html('a').attr('href');
                        var post = {description: description, date: date, link: link};
                        pool.query('INSERT INTO db SET ?', post, function (err, result) {
                            if (err) {
                                console.log(err);
                            }
                        });
                    }
                });
            }).catch(function (err) {
                console.error(err);
            });

After about 100 iterations, I get this error:

{ ResponseTimeoutError: Response timeout for 5000ms, GET http://www.streetinsider.com/stock_lookup_news.php?q=CREG&type=major_news -1 (connected: true, keepalive socket: false)
headers: {}
    at Timeout._onTimeout (/Users/max/projects/stock-news-angular/node_modules/urllib/lib/urllib.js:715:15)
    at tryOnTimeout (timers.js:232:11)
    at Timer.listOnTimeout (timers.js:202:5)
  name: 'ResponseTimeoutError',
  requestId: 595,
  data: undefined,
  path: '/stock_lookup_news.php?q=CREG&type=major_news',
  status: -1,
  headers: {},
  res: 
   { status: -1,
     statusCode: -1,
     headers: {},
     size: 0,
     aborted: false,
     rt: 10030,
     keepAliveSocket: false,
     data: undefined,
     requestUrls: [ 'http://www.streetinsider.com/stock_lookup_news.php?q=CREG&type=major_news' ],
     timing: null,
     remoteAddress: '162.242.133.50',
     remotePort: 80 } }

How can I go about increasing the timeout so that I can finish the loop and insert all the required data into my MySQL db? I think I am not correctly understanding how to set the timeout, as npm's urllib does have an option to set that.

javascript mysql node.js urllib