Search⌘ K

Retrieving and Sending Tweets in Node.js

Explore how to use Node.js and the RxJS library to connect to Twitter streams and filter tweets by geographic locations linked to earthquake epicenters. Understand the process of accumulating location boundaries, updating streams dynamically, and sending relevant tweets to a browser dashboard.

We'll cover the following...

We’re using the streaming Twitter client for Node.js twit to connect to Twitter and search for tweets. From now on, all the code in the server will happen inside the onConnect function, because it assumes that a connection to a WebSocket is already established.

Let’s initialize the stream of tweets in index.js:

Javascript (babel-node)
var stream = T.stream('statuses/filter',
{
track: 'earthquake',
locations: []
});

Filtering the earthquake location

This tells our Twit instance T to start streaming Twitter statuses, filtered by the keyword “earthquake.” This is, of course, very generic and not directly related to the earthquakes happening right now. However, we should take note of the empty locations array. This is an array of latitude and ...