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)�� �"� �/�Tm5��ڵ�����u�\%L��9Ѩ������G�q93�3B����30i��T��}�ih�PN%�Z�G�G6��P����܇�N�9e��G�#6rlߨ��(����J q � &e��L2!�eRD&��Qʉ�)��h2��u������' E/jX�tP�R�ON�wj�ت�­|�� C���EH8�m/v�-�0���� �G;�����n���ɦn�z��|E�7 ��׽� ��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�uL�,��8�4���8?]��÷�V�1�nQ� �v����'#��]���22�$ሓ�����p�����R�M�-u���X ���BF ���'�

Does anyone know what I'm doing wrong? Thanks!


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.

  • Wow thanks! You are a hero of the people! – Alex V Nov 19 '18 at 16:44
  • You're welcome. If you haven't figured out how to add GZIP support yet, I found a Stack Overflow answer which should help. – Glorfindel Nov 19 '18 at 17:00
  • Oh I found an answer here on stackapps that does the trick. Thanks! – Alex V Nov 19 '18 at 17:13

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