title: How to fix error 504: Gateway Timeout in express.js (v 4.0.0)?
body: <p>I am developing a server with express.js, which makes requests to github api to get the users's repositories within webhooks. The problem is that this request returns:</p>
  
  <pre><code>problem with request: timed out
  [error] { [Error: 504: Gateway Timeout]
  [error]   defaultMessage: 'Gateway Timeout',
  [error]   message: '504: Gateway Timeout',
  [error]   code: '504' } 
  </code></pre>
  
  <p>My code:</p>
  
  <ul>
  <li><p>Service: </p>
  
  <p>exports.getWebHooks = function getWebHooks (githubtoken, arrRepos){</p>
  
  <pre><code>var promise = new Hope.Promise();
  
  var arrReposDef = [];
  
  var github = new GitHubApi({
      version: "3.0.0",
      debug: true,
      protocol: "https",
      host: "api.github.com", // should be api.github.com for GitHub
      timeout: 5000,
      headers: {
          "user-agent": "Meanstack" // GitHub is happy with a unique user agent
      }
  });
  
  
  github.authenticate({
      type: "oauth",
      token: githubtoken.token
  });
  
  
  async.each(arrRepos,
  
      function(item, callback){
          // It runs well
  
          github.repos.getHooks({
  
              user: githubtoken.username,
              repo: item.name,
  
              headers: {
                  "X-GitHub-OTP": "two-factor-code"
              }
  
          }, function(err, res) { 
              if (err) { // it runs wrong 2 times, this the error that I defined up.
                  console.log(err);
                  githuberror = true;
  
              }
  
               else{ // it runs well 2 times
  
  
  
                  if(!res.length){
  
                      arrReposDef.push(item);
  
  
                  }
  
                  else{
                      var enc = false;
  
                      for(var i = 0; i&lt; res.length; i++){
                          if(res[i].config !== undefined &amp;&amp; res[i].config !== null){
                              if(res[i].config.url !== undefined &amp;&amp; res[i].config.url !== null){
  
  
  
                                  if(res[i].config.url !== config.githubcallback){
  
                                       enc = true;
  
  
                                  }
                              }
  
                          }
                      }
                      if(enc) {
  
  
                          arrReposDef.push(item);
  
  
                      }
  
  
                  }
  
  
  
              }
              callback(); //required
          });
      },
  
      // 3rd param is the function to call when everything's done
      function(err){
  
          if(err){
              console.log('Error:' + err);
              return promise.done(err,null);
          }
  
          // All tasks are done now
          else{
  
              return promise.done(null,arrReposDef);
  
  
          }
      }
  );
  
  return promise;
  </code></pre>
  
  <p>};</p></li>
  </ul>
  
  <p>I know the application flow thanks to cmd result:</p>
  
  <pre><code>REQUEST:  { host: 'api.github.com',
    port: 443,
    path: '/repos/1izpena/angularProject/hooks?access_token=secret',
    method: 'get',
    headers: 
     { host: 'api.github.com',
       'content-length': '0',
       'x-github-otp': 'two-factor-code',
       'user-agent': 'Meanstack',
       accept: 'application/vnd.github.v3+json' } }
  entro en webhooks, dentro del callback
  REQUEST:  { host: 'api.github.com',
    port: 443,
    path: '/repos/1izpena/ionicProject/hooks?access_token=secret',
    method: 'get',
    headers: 
     { host: 'api.github.com',
       'content-length': '0',
       'x-github-otp': 'two-factor-code',
       'user-agent': 'Meanstack',
       accept: 'application/vnd.github.v3+json' } }
  entro en webhooks, dentro del callback
  REQUEST:  { host: 'api.github.com',
    port: 443,
    path: '/repos/1izpena/ionicProjectDef/hooks?access_token=secret',
    method: 'get',
    headers: 
     { host: 'api.github.com',
       'content-length': '0',
       'x-github-otp': 'two-factor-code',
       'user-agent': 'Meanstack',
       accept: 'application/vnd.github.v3+json' } }
  entro en webhooks, dentro del callback
  REQUEST:  { host: 'api.github.com',
    port: 443,
    path: '/repos/1izpena/RestAPI/hooks?access_token=secret',
    method: 'get',
    headers: 
     { host: 'api.github.com',
       'content-length': '0',
       'x-github-otp': 'two-factor-code',
       'user-agent': 'Meanstack',
       accept: 'application/vnd.github.v3+json' } }
  STATUS: 200
  HEADERS: {"server":"GitHub.com","date":"Fri, 15 Apr 2016 18:56:08 GMT","content-type":"application/json; charset=utf-8","content-length":"2","connection":"close","status":"200 OK"..."x-github-request-id":""}
  entro en webhooks, no hay errores
  entro en webhooks, en if
  STATUS: 200
  HEADERS: {"server":"GitHub.com","date":"Fri, 15 Apr 2016 18:56:08 GMT","content-type":"application/json; charset=utf-8","content-length":"2","connection":"close","status":"200 OK"...,"x-github-request-id":""}
  entro en webhooks, no hay errores
  entro en webhooks, en if
  problem with request: timed out
  [error] { [Error: 504: Gateway Timeout]
  [error]   defaultMessage: 'Gateway Timeout',
  [error]   message: '504: Gateway Timeout',
  [error]   code: '504' } null 1izpena
  { [Error: 504: Gateway Timeout]
    defaultMessage: 'Gateway Timeout',
    message: '504: Gateway Timeout',
    code: '504' }
  problem with request: timed out
  [error] { [Error: 504: Gateway Timeout]
  [error]   defaultMessage: 'Gateway Timeout',
  [error]   message: '504: Gateway Timeout',
  [error]   code: '504' } null 1izpena
  { [Error: 504: Gateway Timeout]
    defaultMessage: 'Gateway Timeout',
    message: '504: Gateway Timeout',
    code: '504' }
  </code></pre>
  
  <p>Any idea? Many thanks.</p>