stweam

Streams the public Twitter stream.

Usage no npm install needed!

<script type="module">
  import stweam from 'https://cdn.skypack.dev/stweam';
</script>

README

stweam

build status coverage status npm version npm downloads dependency status devDependency status

Streams the public Twitter stream.

Note that the output is the "raw" Twitter stream, so you'll need to process it appropriately. Processing was deliberately left out of this module, so that you can choose your poison(s) via npm.

Requirements

  • Node.js version 0.11.x (for the harmony flag which exposes generators)
  • Keys obtained from dev.twitter.com after setting up a new app

Installation

$ npm install stweam --save

Example

// => example.js

var Stweam = require('stweam');
var stream = require('stream');
var dest = new stream.PassThrough();

var stweam = new Stweam({
  consumerKey: 'consumerKey',
  consumerSecret: 'consumerSecret',
  token: 'token',
  tokenSecret: 'tokenSecret'
});

// Optionally hook into log messages...
stweam.on('info', function(msg){
  // Do something with msg.
});

// ... or warn messages.
stweam.on('warn', function(msg){
  // Do something with msg.
});

// stweam is a Stream.
stweam.pipe(dest);

stweam
  .language('fr')
  .track('beaker')
  .follow('12345')
  .start();

To run:

$ node --harmony example.js

Also, check out chirp to see Stweam in action.

API

var stweam = new Stweam(opts)

Initialise a new Stweam with the given opts.

opts should contain:

  • consumerKey
  • consumerSecret
  • token
  • tokenSecret

stweam.track(keywords)

Set the phrases that will determine what is delivered on the stream.

See: track.

stweam.language(language)

Set the Tweet language, defaults to en.

See: language.

stweam.follow(userids)

Set the users whose Tweets will be delivered on the stream.

See: follow.

stweam.start()

Start the app.

Events

Note: I like Bunyan's opinions on log levels :)

stweam.on('info', function(msg){})

Provides detail about regular operation, rather than spamming stdout.

stweam.on('warn', function(msg){})

Might want to take a closer look at this one.

Tests

To run:

$ npm run test:spec

To generate a coverage report:

$ npm run test:cov

Credits