I have the following simple Coffeescript code to access the Twitter Stream API
http = require 'http'
options =
port: 443
host: 'stream.twitter.com'
path: '/1.1/statuses/filter.json?track=keyword'
headers:
'Authorization': 'Basic ' + new Buffer('[user]:[pass]').toString 'base64'
'Host': 'stream.twitter.com'
method: 'GET'
callback = (res) ->
console.log res
res.on 'data', (chunk) ->
console.log chunk
res.on 'end', -> console.log 'end'
# res.on 'close', -> res.emit 'end'
http.request options, callback
Why am I getting
throw arguments[1]; // Unhandled 'error' event
Error: socket hang up
An error is triggering the error
event on your response (res
), which you are not listening for. By default, error
events in Node.js EventEmitters, if not listened for, will throw. You need to add
res.on 'error', # whatever
and handle the error.
Note that this will just keep the error from being thrown; it won't stop the error from occurring.