If I browse to https://api.stackexchange.com/2.2/search?site=stackoverflow&tagged=racket via Chrome, it displays a bunch of JSON containing the appropriate content. But when I run the following NodeJS program:

var request = require("request");
var EventEmitter = require("events").EventEmitter;
var body = new EventEmitter();

request("https://api.stackexchange.com/2.2/search?site=stackoverflow&tagged=racket", function(error, response, data) {
body.data = data;

body.on('update', function () {
console.log(body.data); // HOORAY! THIS WORKS!

Which should display the same content, I get a bunch of garbled symbols, like this:

�u1@�@�P��e�c�4���b0d�ysDl6�F�O���`�:cד�xۼ]�ɦi����Gplپ�d{k��EFPt��^v�c�<��Y@rI9��   2F��I�*�uBI%q��f)�� �"�
                                                         q  �
��׽�            ��i��<,��Hj���d�:���t(��5�Q�:O�M�����^��LZ��`�����iH�����@�'N8���hA�h��hD����,М��Y�)`�j�KS:_
     �^lV���T9����@߁�K��������� ��� �Ǒs�����    E��q�Xf�
yM�K�u`L�,��8�4���8?]��÷�V�1�nQ�    �v����'#��]���22�$ሓ�����p�����R�M�-u���X
���BF  ���'�

Does anyone know what I'm doing wrong?


I've been bitten by this feature as well in the past...

Responses from the API are compressed with GZIP (by default; you can request DEFLATE as well). Your browser automatically knows how to handle this; with most development libraries you have to specify explicitly that you want support for compression.

I don't have experience with the 'request' library in NodeJS, but the solution in this Stack Overflow answer should work. You don't need to add the 'Accept-Encoding': 'gzip' header, though.


Not the answer you're looking for? Browse other questions tagged .