title: How to deploy a Node.js WebSocket server to Amazon Elastic Beanstalk?
body: <p>Using the Elastic Beanstalk web console, I've launched a new Web Server 1.0 environment with:</p>
  
  <ul>
  <li>Predefined configuration: Node.js, 64bit Amazon Linux 2014.09 v1.0.9</li>
  <li>Environment type: Load balancing, autoscaling</li>
  </ul>
  
  <p>and have <a href="https://stackoverflow.com/a/16064334/242933">set Proxy Server to none</a>.</p>
  
  <p>I've successfully compressed &amp; uploaded via the console my code:</p>
  
  <p>package.json</p>
  
  <pre><code>{
    "name": "cool",
    "version": "0.0.0",
    "dependencies": {
      "ws": "0.4.x"
    }
  }
  </code></pre>
  
  <p>server.js</p>
  
  <pre><code>var wss = new (require('ws')).Server({port: (process.env.PORT || 3000)})
  wss.on('connection', function(ws) {
    console.log('connected')
    ws.on('message', function(message) {
      console.log(message)
      ws.send(message)
    });
    ws.on('close', function() {
      console.log('disconnected')
    })
  })
  </code></pre>
  
  <p>I also tried including the <code>node_modules</code> directory.</p>
  
  <p>After running:</p>
  
  <pre><code>wscat -c ws://default-environment-xxxxxxxxxx.elasticbeatalk.com/
  </code></pre>
  
  <p>I got back:</p>
  
  <pre><code>Error: unexpected server response (200)
  </code></pre>
  
  <p>How can I find out more about that error?</p>
  
  <p>Amazon sets the PORT environment variable to 8080. So, I also tried:</p>
  
  <pre><code>wscat -c ws://default-environment-xxxxxxxxxx.elasticbeatalk.com:8080/
  </code></pre>
  
  <p>But, that just hung and then returned:</p>
  
  <pre><code>Error: connect ETIMEDOUT
  </code></pre>
  
  <p>Also, when I do establish a WebSocket connection, I want the server to allow it to stay open indefinitely, unlike Heroku's WebSocket implementation, which times out after 60 seconds.</p>
  
  <p>Is there a detailed tutorial on how to do this?</p>