npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twitter-stream-client

v0.11.3

Published

A daemon listening to Twitter streaming API

Downloads

18

Readme

TwitterStreamClient is a client for the Twitter Streaming API

Quick start

To install TwitterStreamClient, run:

npm install twitter-stream-client

A simple Twitter Stream client would be:

var TwitterClient = require('twitter-stream-client');
var twitterClient = new TwitterClient ({
        OAuth: {
            consumerKey: 'TWITTER CONSUMER KEY',
            consumerSecret:  'TWITTER CONSUMER SECRET',
        },
        keywords: '#hashtag',
        accessToken: 'TWITTER ACCESS TOKEN',
        accessTokenSecret: 'TWITTER ACCESS TOKEN SECRET'
});

twitterClient.on('newtweet', function (tweet) {
    console.log(tweet.text);
});

Events

TwitterStreamClient is an EventEmitter and sends the following events:

  • connected: when we have a response from Twitter
  • twitterdown: when we did not get the keep alive tick from Twitter for longer than keepAliveTime (see API#constructor)
  • newtweet: when we have a new tweet from Twitter, the parsed tweet is passed as a parameter to the callback
  • missedtweets: when twitter sends a "limit" error, we emit this event with the number of missed tweets on this particular time (not the total)
  • error: when the connection request gets an error code as a response or Twitter sends a string that is not JSON

API

TwitterClient (options, proxy)

TwitterClient is the constructor and has two arguments:

options is a hash which must contain:

  • OAuth, a hash containing consumerKey (you Twitter consumer key) and consumerSecret (your Twitter consumer secret)
  • keywords (string), a comma-separated list of keywords to wtach on Twitter
  • accessToken (string), your Twitter access token
  • accessTokenSecret (string), your Twitter access token secret

options can also contain:

  • keepAliveTime (integer), default 64000, if Twitter does not send a keep alive tick after this duration, we consider the connection is lost and send twitterdown event and restart the client
  • trackRequest (string), default '/1.1/statuses/filter.json?stall_warnings=true&track', can be used to change the streaming API we use
  • host (string), default 'stream.twitter.com',
  • port (string), default '443',
  • languagesFilter (string), comma separated list of languages (Twitter codes) to add as filter to the request default ''

If set proxy is a hash which must contain:

  • host (string), the host of your proxy
  • port (string), the port of your proxy

connect ()

Actually connects to Twitter API, if you save the tweets in the listener of newtweet event, the database must be ready and connected before calling connect().

disconnect ()

Disconnect from Twitter API

Licence

MIT