Book Image

Node.js By Example

Book Image

Node.js By Example

Overview of this book

Table of Contents (18 chapters)
Node.js By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Bringing Socket.IO to the project


Socket.IO (http://socket.io/) is a real-time engine built on the top of WebSockets technology. It is a layer that makes web development easy and straightforward. Like every new thing nowadays, WebSockets comes with its own problems. Not every browser supports this technology. We may have problems with the protocol and missing events such as heartbeats, timeouts, or disconnection support. Thankfully, Socket.IO fixes these issues. It even provides fallbacks for the browsers that do not support WebSockets and goes with techniques such as long-polling.

Before making changes in our backend, we need to install the module. The engine is distributed in the same way as every other Node.js module; it is available via the package manager. So, we have to add Socket.IO to the package.json file in the following way:

{
  "name": "nodejs-by-example",
  "version": "0.0.2",
  "description": "Node.js by example",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies...