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

fetch-tweets

v0.1.7

Published

A node module that fetches tweets from Twitter based on topic, location, timeframe or combination

Downloads

11

Readme

fetch-tweets

A simple to use, feature-rich, tested node module for fetching Tweets from the Twitter API.

Install

npm install fetch-tweets --save

Set up

Create a new Twitter app here to get your consumer key and secret.

Include the following code in your file.

var FetchTweets = require('fetch-tweets'); // Include the module

// Specify Twitter keys (preferably in an external .gitignore'd file)
var apiKeys = {
    consumer_key : 'XXXXXXXXXXXXXXXXXXXXXXXXX',
    consumer_secret : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
};

// Create a new object and pass in keys and optional additional options (see below)
var fetchTweets = new FetchTweets(apiKeys); 

The above code: includes the fetch-tweets module, creates a new instance and passes in your Twitter API keys.

Fetching Tweets by keyword(s)

There are two methods of selecting Tweets by keyword, using Twitter search API.

  • Single paramater string containing the search term
  • Single paramater JSON object containing options

Simple example

fetchTweets.byTopic('JavaScript', function(results){
   console.log(results); // Do whatever with the results
});

There are a series query operators that can be used inside this string parameter, such as fetching Tweets containg multiple keywords. To view a list of query operators click here.

Specifying more options

You can also search for Tweets by passing in a JSON object containing options set by the Twitter API. There is an extensive list of options such as dates, locations, languages and popularity. For example:

var options = {
  q: 'banana',
  lang: 'en',
  result_type: 'popular',
  count: 5,
}

fetchTweets.byTopic(options, function(results){
   console.log(results); // Do whatever with the results
});

View the full list of what you can pass in as options here in the Twitter documentation

The Results

There are two options for how you'd like your results returned:

  • Formatted Results - just the useful stuff (default)
  • Full Results - everything that is returned by the Twitter API

Formated Results (just the usefull stuff)

This is default, so you don't need to do anything different than above

Results will be returned in the following format:

[
    {   date: 'Sun Aug 30 15:55:09 +0000 2015',
        body: 'JavaScript is just so totally awesome',
        location: { geo: null, coordinates: null, place: null },
        'retweet-count': 23952,
        'favorited-count': 0,
        lang: 'en' },
    {   date: 'Sun Aug 30 15:55:09 +0000 2015',
        body: 'Ony one thing more awesome than JavaScript and that's CoffeeScript!!',
        location: { geo: null, coordinates: null, place: null },
        'retweet-count': 0,
        'favorited-count': 0,
        lang: 'en' },
    {   date: 'Sun Aug 30 15:55:08 +0000 2015',
        body: 'And the one thing more awesome than CoffeeScript, Coffee!!!!',
        location: { geo: null, coordinates: null, place: null },
        'retweet-count': 0,
        'favorited-count': 0,
        lang: 'en'
    }
]

Full Results

If you would like the full results returned by the Twitter API, then you can specify the second parameter as false when creating the fetchTweets object:

var FetchTweets = require('fetch-tweets');
var fetchTweets = new FetchTweets(apiKeys, false);

You can view an example of the format of these results here, on the Twitter website

Tests

fetch-tweets uses Mocha, Chai, Sinon and Istanbul to form it's testing environment.

To run all tests: npm test

Summary of test results will be outputed to the console, more detailed results are generated and saved in the reports directory

Building

fetch-tweets uses gulp to prepare all the files

Run gulp build to build

Run gulp test to test

Run gulp To clean directory, build, test, and watch for changes rebuilding when a file is modified

License

MIT � Alicia Sykes