title: Node.js & the instagram API, 'Could not decode a text frame as UTF-8'
body: <p>I am doing a simple instagram API call with the http node.js module.  Just a simple request like this:</p>
  
  <pre><code>getJSON : function(options, on_result, on_error) {
  
      var req = http.request(options, function(res) {
  
          var output = '';
          res.setEncoding('utf8');
  
          res.on('data', function (chunk) {
              console.log(chunk);
              return output += chunk;
          });
  
          return res.on('end', function() {
              var obj = JSON.parse(output);
              on_result(res.statusCode, obj);
          });
      });
  
      req.on('error', function(err) {
          on_error(err);
      });
  
      return req.end();
  }
  </code></pre>
  
  <p>The on_result function just stringifies it with JSON.stringify, and sends it across a web socket with this function: </p>
  
  <pre><code>var connection = request.accept(null, request.origin);
  connection.sendUTF(JSON.stringify(obj));
  </code></pre>
  
  <p>When I start the node server and point my browser to my url, I get this from chrome and firefox: </p>
  
  <blockquote>
    <p>Could not decode a text frame as UTF-8.</p>
  </blockquote>
  
  <p>I had absolutely no problems running this yesterday.</p>
  
  <p>In the http 'on data' function, I am logging out the data to the console, and what I see onscreen looks ok except certain escape characters like these:</p>
  
  <pre><code>"text":"\ud83d\ude1d\ud83d\ude02\ud83d\udc4f\ud83d\udc8b"
  "full_name":"\ud83c\uddee\ud83c\uddf9\u21e8\u261eSara\u261c\u21e6\ud83c\uddee\ud83c\uddf9"
  </code></pre>
  
  <p>Then, when it gets JSON stringified, these escape sequences turn into this:</p>
  
  <pre><code>"text":"&lt;d83d&gt;&lt;de1d&gt;&lt;d83d&gt;&lt;de02&gt;&lt;d83d&gt;&lt;dc4f&gt;&lt;d83d&gt;&lt;dc8b&gt;"
  "full_name":"&lt;d83c&gt;&lt;ddee&gt;&lt;d83c&gt;&lt;ddf9&gt;â¨âSaraââ¦&lt;d83c&gt;&lt;ddee&gt;&lt;d83c&gt;&lt;ddf9&gt;"
  </code></pre>
  
  <p>Which explains why the browsers complain about UTF-8.  </p>
  
  <p>Am I doing something wrong?  </p>