O'Reilly logo

Node.js Essentials by Fabian Cook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Socket.IO

Simple HTTP is great for things that don't need real-time data, but what about when we need to know about things as they happen. For example, if we were creating a website that had a chat interface or similar?

This is when something like Web sockets come into play. Web sockets are usually referred to as WebSockets and are full duplex or two-way low-latency communication channels. They are generally used by messaging applications and games where messages need to be relayed between the server and client. There is a really handy npm module called socket.io, which can add Web sockets to any Node.js application.

To install it we just need to run:

[~/examples/example-27] npm install socket.io

Socket.IO can be set up very simply to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required