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.

Discover whether there is more love or hate in the world by using real-time data from Twitter

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:

You open a connection to the API server.

You send a request for some data.

You receive the data that you requested from the API.

The connection is closed.

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

You open a connection to the API server.

You send a request for some data.

Data is pushed to you from the API.

The connection remains open.

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.