title: Nodejs http retry on timeout or error
body: <p>I'm trying to automatically retry HTTP requests on timeout or error. <br/>Currently my code looks like this:</p>
  
  <pre><code>var req = http.get(url, doStuff)
                .on('error', retry)
                .setTimeout(10000, retry);
  </code></pre>
  
  <p>However, a single request can sometimes trigger both "on error" and "timeout" events. What is a better way of implementing retry?</p>