title: node.js program quits before message from server is recieved
body: <p>I'm a fresh coder, and writing a chatbot for discord, a gaming voip service. The API uses Websockets to communicate with their servers. Here's the code, with the API tokens, etc redacted...</p>
  
  <pre><code>var https = require('https');
  var ws = require('ws');
  var client = {};
  var connected = false;
  
  var tok = 'token';
  function webSocket(callback) {
    return https.get({
      host: 'discordapp.com',
      path: '/api/gateway',
      headers:{
        token: tok,
        userAgent: 'User-Agent: DiscordBot($http://www.thegamingpub.net, $v0001)'
      }
    }, function(response){
      var body = '';
      response.on('data', function(d){
        body += d;
      });
      response.on('end', function(){
        var parsed = JSON.parse(body);
        console.log(parsed);
        callback(parsed.url);
      });
    });
  }
  webSocket(function(url){
    var identify = JSON.stringify({
      token: tok,
      properties:{
        $os: 'windows10',
        $browser: 'discordhal',
        $device: 'discordhal',
        $referrer: '',
        $referring_domain: ''
      },
      compress: false,
      large_threshold: 250
    });
    client = new ws(url);
    client.on('open', function(){
      client.send(identify);
      connected = true;
    });
    client.on('message', function(d){
      console.log(d);
    });
    client.on('error', function(d){
      console.log(d);
    });
  });
  </code></pre>
  
  <p>The code above has to get the websocket url from the server, then create a new websocket connection called 'client' using the ws url. The client.send callback is firing when the connection opens, but then the program exits before it can receive a message from the server. I know the issue is in my logic, but I'm not sure where. There is no error message in the process or in any of the modules. Can anyone tell me why the program exits?</p>