Programming Socket.io

Probably, the top feature in our web application is its ability to send updates directly from the server to the client in real time. To fully implement this feature, we need to call the model's listenForUpdates() function and push the resulting data to all connected clients.

At the start of this chapter, you learned about the Socket.io module, which allows you to send data to clients using WebSockets; so, we're going to use this module to push changes to our users' browsers. You may remember that we initialized the Socket.io module in the app.js file, so we're now going to edit the file; in particular, we're going to edit the server.listen() function:

server.listen(8000, function() { console.log"Server up and listening on port ...

Get Getting Started with RethinkDB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.