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-cli

v0.2.1

Published

Twitter streams cli tool

Downloads

63

Readme

twitter-stream-cli 0.2.1

Twitter streams. This is a cli tool and also a npm lib.

  • Track multiples words
  • Output results in several formats
  • Send results to a Firebase Database
  • Instructions to run severals instances with pm2

Install

This tool requires node.js. I suggest you to use nvm

asciicast

npm install twitter-stream-cli -g

Configure .env file

  1. Create an .env file:
touch .env
# or use wget
wget https://raw.githubusercontent.com/saitodisse/twitter-stream-cli/master/.env-example -O .env
  1. Create an app on https://apps.twitter.com/ and put keys on .env file:
# Twitter API keys: https://apps.twitter.com
CONSUMER_KEY=__XXX__
CONSUMER_SECRET=__XXX__
TOKEN=__XXX__
TOKEN_SECRET=__XXX__

# [optional] Firebase: https://console.firebase.google.com
FIREBASE_APIKEY=__XXX__
FIREBASE_DATABASEURL=__XXX__

Run as cli tool

asciicast

# will track banana
twitter-stream-cli banana

# will track banana tweets OR chocolate tweets
twitter-stream-cli banana chocolate

# will track banana and chocolate in the same tweet message
twitter-stream-cli "banana chocolate"

Format output

twitter-stream-cli banana --short          #output: @user (lang): 80 char tweet text
twitter-stream-cli banana --long           #output: @user (lang, id, date): full tweet text
twitter-stream-cli banana --json           #output: full json result
twitter-stream-cli banana --json-formatted #output: full formatted json result
twitter-stream-cli banana --json-inspect   #output: inspect json result with colors

Send json result to Firebase

  1. Edit .env file. Replace __XXX__ on FIREBASE_URL=https://__XXX__.firebaseio.com:

  2. Send results

twitter-stream-cli banana --send

Run multiples instances with pm2

We can easily run multiples instances of this tool with pm2.

Install pm2

npm i pm2 -g

Create configuration files

Create app.json

mkdir pm2
touch pm2/app.json

Edit app.json:

{
  "apps" : [
    {
      "name"              : "banana",
      "script"            : "twitter-stream-cli",
      "args"              : ["banana"],
      "log_date_format"   : "YYYY-MM-DD HH:mm:ss Z",
      "autorestart"       : true,
      "exec_mode"         : "fork",
      "max_memory_restart": "100M",
    },
    {
      "name"              : "chocolate",
      "script"            : "twitter-stream-cli",
      "args"              : ["chocolate"],
      "log_date_format"   : "YYYY-MM-DD HH:mm:ss Z",
      "autorestart"       : true,
      "exec_mode"         : "fork",
      "max_memory_restart": "100M",
    },
  ]
}

Now you can start watching banana & cholocate in separeted instances. This will send to differents firebase URLs.

# edit pm2/app.json with your tracking terms
pm2 start pm2/app.json

Check is everything is running ok:

# you can see logs and monitore
pm2 list
pm2 monit

# delete and stop all instances
pm2 delete all

Use as lib

Install

npm install twitter-stream-cli --save

Use

// ES5
var TwiterStream require('twitter-stream-cli');
var twiterStream = new TwiterStream({
  track: 'banana'
});
return twiterStream.run();
// ES6
import TwiterStream from 'twitter-stream-cli';
const twiterStream = new TwiterStream({
  track: 'banana'
});
return twiterStream.run();

Test and run locally

git clone [email protected]:saitodisse/twitter-stream-cli.git
cd twitter-stream-cli
npm install
npm test
node ./bin/twitter-stream-cli.js -h

# all available tasks
gulp help