title: nodejs-websocket unhandled error
body: <p>Sorry if this is a stupid question, I am new to node.js and server-side in general.</p>
  
  <p>I am working on a webapp with a node.js server-side, and have gotten mostly everything working using websockets. One problem I am having, though, is that when I close a tab, my server crashes with the error:</p>
  
  <pre><code>events.js:182
      throw er; // Unhandled 'error' event
      ^
  </code></pre>
  
  <p>Heres my server-side code: </p>
  
  <pre><code>var ws = require("nodejs-websocket")
  var owjs = require("overwatch-js");
  var fs = require("fs");
  
  console.log("Opening server on port 8003...");
  
  var options = {
      secure: true,
      key: fs.readFileSync("key.pem"),
      cert: fs.readFileSync("cert.pem")
  }
  
  var server = ws.createServer(options, function (conn) {
  
      // When we get a username
      conn.on("text", function (str) {
  
          // Get user stats
          owjs
              .getOverall('pc', 'us', str)
              // Send data back to client
              .then((data) =&gt; conn.sendText(JSON.stringify(data)));
  
      });
  
      conn.on("close", function (code, reason) {
          console.log("Connection closed")
      });
  
  }).listen(8003);
  </code></pre>
  
  <p>I'm pretty sure I need to handle the error (obviously) but dont know how to do it. Do I use .on("error") after .listen? I tried that but i'm not sure if I did it right. </p>
  
  <p>Any help or guidance would be greatly appreciated.</p>