Home > Articles > Open Source > Ajax & JavaScript

Using Node.js and Socket.IO with Twitter’s Streaming API

  • Print
  • + Share This
  • 💬 Discuss
Learn about how Node.js and Socket.IO can be used to consume data directly from the Web and then broadcast the data to connected clients. You will be working with Twitter’s streaming Application Programming Interface (API) and pushing data out to the browser in real-time.

Streaming APIs

In Hour 13, “A Socket.IO Chat Server,” you learned how to create a chat server with Socket.IO and Express. This involved sending data from clients (or browsers) to the Socket.IO server and then broadcasting it out to other clients. In this hour, you learn about how Node.js and Socket.IO can also be used to consume data directly from the Web and then broadcast the data to connected clients. You will be working with Twitter’s streaming Application Programming Interface (API) and pushing data out to the browser in real-time.

With Twitter’s standard API, the process for getting data is as follows:

  1. You open a connection to the API server.
  2. You send a request for some data.
  3. You receive the data that you requested from the API.
  4. The connection is closed.

With Twitter’s streaming API, the process is different:

  1. You open a connection to the API server.
  2. You send a request for some data.
  3. Data is pushed to you from the API.
  4. The connection remains open.
  5. More data is pushed to you when it becomes available.

Streaming APIs allow data to be pushed from the service provider whenever new data is available. In the case of Twitter, this data can be extremely frequent and high volume. Node.js is a great fit for this type of scenario where large numbers of events are happening frequently as data is received. This hour represents another excellent use case for Node.js and highlights some of the features that make Node.js different from other languages and frameworks.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus