title: Why won't my app establish websocket connection on Heroku?
body: <p>I am trying to deploy my nodejs app on heroku. I cannot get the websocket connection to establish. I have read everything I could find, tried every example and none of them seem to work for me.</p>
  
  <p>I when I try to open my page "heroku open", nodejs is correctly giving me the html file. However, the websocket 'ws' connection never establishes.</p>
  
  <p>My server.js has these configurations:</p>
  
  <pre><code>var pport = process.env.PORT || 5000;
  server.listen(pport, function(err) {
      if(!err) { console.log("Listening on port " + pport); }
  });
  </code></pre>
  
  <p><strong>Side Note</strong> 
  When I check "heroku logs", I find that the port my app is running on is a random 5 digit number. ( like 28896, 53365, etc.) It never actually runs on the second half || 5000.</p>
  
  <p>But the thing is, in order for my game.html file to establish a websocket connection, it needs to know what port.
  I have tried the following client configurations, none have worked:</p>
  
  <p><strong>1)</strong></p>
  
  <pre><code>var host = location.origin.replace(/^http/, 'ws');
  this.connection = new WebSocket(host);
  </code></pre>
  
  <p><strong>2)</strong></p>
  
  <pre><code>var host = location.origin.replace(/^http/, 'ws');
  host = host + ":5000";
  this.connection = new WebSocket(host);
  </code></pre>
  
  <p><strong>3)</strong></p>
  
  <pre><code>this.connection = new WebSocket('ws://infinite-earth-7708.herokuapp.com/');
  </code></pre>
  
  <p>I have also done what their website said, and attempted to use the following after deploying my app:</p>
  
  <pre><code>heroku config:add NODE_ENV=production
  </code></pre>
  
  <p>Please advise</p>