twit-stream

A read stream for streaming Twitter data

twit-stream

A simplification for reading Twitter data using Node.JS Streams. Pass in OAuth info and select Twitter stream method, and get a Node stream2 returned. Choose whether you want a stream of objects (objectMode: true) or a stream of buffers.

npm install --save twitter-stream
 
var Twitter = require('twit-stream');
 
var options = {
  consumer_key: '',
  consumer_secret: '',
  oauth_token: '',
  oauth_secret: ''
};
 
var stream = new Twitter(options).filter({ track: 'Javascript' });
 
stream.pipe(objectHandler);
// Where objectHandler is an arbitrary write stream 

See more examples

See information about the different end points on the Twitter Developer site

Parameter: option is object of options.
Returns: Twitter instance

Options must contain OAuth info

{
  "consumer_key": "",
  "consumer_secret": "",
  "oauth_token": "",
  "oauth_secret": ""
}

In addition to OAuth data, options allow you to define if the returned streams should be in objectMode or not.

Type: Boolean
Default: true

With object mode the data passed is a stream of Twitter objects. By setting the objectMode to false, the streamed data is a stream of buffered strings, one tweet buffered up at the time.

objectMode: false could be used to pipe twitter data directly to file or to any other write stream requiering buffers.

Parameter: data is request payload values (POST body) as documented by Twitter dev site.
Returns: Stream (with objectMode: true)

Parameter: params is values as documented by Twitter dev site
Returns: Stream (with objectMode: true)

Parameter: params is values as documented by Twitter dev site
Returns: Stream (with objectMode: true)

Note: You need special premissions by Twitter to have access to the firehose endpoint.

options.objectMode = false;
new Twitter(options).sample()
  // pipe to file 
  .pipe(fs.createWriteStream(__dirname + '/sample.dat'));

MIT License