Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

events.js:85 throw er; // Unhandled 'error' event

I'm trying to setup a twitter app and I'm currently stuck on the following error:

$ node twitter.js
events.js:85
throw er; // Unhandled 'error' event
      ^
SyntaxError: Unexpected token U
    at Object.parse (native)
    at EventEmitter.receive (/Users/user/Documents/twitter/node_modules/twitter/lib/parser.js:40:21)
    at IncomingMessage.<anonymous> (/Users/user/Documents/twitter/node_modules/twitter/lib/twitter.js:207:14)
    at IncomingMessage.emit (events.js:129:20)
    at readableAddChunk (_stream_readable.js:163:16)
    at IncomingMessage.Readable.push (_stream_readable.js:126:10)
    at HTTPParser.parserOnBody (_http_common.js:132:22)
    at TLSSocket.socketOnData (_http_client.js:317:20)
    at TLSSocket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
MBPro:twitter $ 

Synthax error? I don't understand.

Twitter.js code:

var tweet = require('twitter'),
    twitter = new tweet({
        consumer_key: '',
        consumer_secret: '',
        access_token_key: '',
        access_token_secret: ''
    });

var count = 0,
    util = require('util');

twitter.stream('filter', {track: 'test'}, function(stream){

    stream.on('data', function(data) {
        console.log(util.inspect(data));
        stream.destroy();
        process.exit(0);
    });

});
like image 606
sslss Avatar asked May 15 '15 14:05

sslss


1 Answers

This is a bug in the twitter module. The module should be checking the HTTP response's Content-Type header value before trying to parse the response as JSON.

Here is the relevant issue on github.

like image 194
mscdex Avatar answered Nov 06 '22 03:11

mscdex