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

tstream

v0.0.9

Published

A Twitter streaming API client

Downloads

30

Readme

tstream

Twitter streaming API client

  • API compliant with ntwitter

ntwitter is a great Twitter client, does a whole log of things, but hasn't seen updates in nearly a year and their streaming API implementation is very limited.

tstream goes a step further and let's you listen to a lot more events

Almost all the message types listed here are fired as events

https://dev.twitter.com/docs/streaming-apis/messages#Stall_warnings_warning

eg. disconnect

Twitter will pass this message in the HTTP stream

{
  "disconnect":{
    "code": 4,
    "stream_name":"< A stream identifier >",
    "reason":"< Human readable status message >"
  }
}

You can listen to it in your code as follows stream.on("disconnect", function(data){});

data will contain what Twitter sent as the "disconnect" object

Stall warnings is another useful one, listen to a "warning" event

If you are dealing with user streams, listen to a "user-event" to be notified about all the events listed here https://dev.twitter.com/docs/streaming-apis/messages#Events_event

Usage

var TStream = require('tstream'),
    config = require('./config.js');

var tstream = new TStream(config.twitter);
tstream.stream('statuses/filter', {'track': ['what']}, function(stream) {
    stream.on('data', function(tweet) {
        console.log(tweet.text);
    });
    stream.on('error', function(error) {
        console.log('stream error - ' + error.message);
    });
    // will be fired when the Twitter streams sends a stall_warning
    // https://dev.twitter.com/docs/streaming-apis/messages#Stall_warnings_warning
    stream.on('warning', function (data) {
        console.log('Twitter stream warning - ' + data);
    });

    // will be fired when the stream is being disconneced by Twitter
    // https://dev.twitter.com/docs/streaming-apis/messages#Disconnect_messages_disconnect
    stream.on('disconnect', function (data) {
        console.log('Twitter stream disconnected - ' + data);
    });
    stream.on('end', function() {
        console.log('stream ended');
    });
});

Pass an object that contains "consumer_key", "consumer_secret", "access_token_key", "access_token_secret" to the TStream constructor. The example code above assumes there is a file in the same directory, called config.js that exports a config object that has a twitter key which again is an object that contains the credentials (access_token etc)

  • TODO: write better docs