title: How do I set a timeout for client http connections in node.js
body: <p>I'm writing a node.js application that needs to talk to a server. It establishes an http connection with the following code:</p>
  
  <pre><code>var client = http.createClient(u.port, u.hostname, u.secure);
  client.on("error", function(exception) {
      logger.error("error from client");
  });
  var request = client.request(method, u.path, headers);
  </code></pre>
  
  <p>I don't see any option in the node.js documentation for setting a timeout on the connection, and it seems to be set to 20 seconds by default. The problem I'm having is that I have users in China on what appears to be a slow or flaky network, who sometimes hit the timeout connecting to our datacenter in the US. I'd like to increase the timeout to 1 minute, to see if that fixes it for them.</p>
  
  <p>Is there a way to do that in node.js?</p>