Setting up Socket.io

To get started, inside the Terminal, let's go ahead and install the most recent version of Socket.io using npm i. The module name is socket.io, and the most recent version at time of writing is @2.0.4. We'll use the --save dev flag to update the package.json file:

npm i socket.io@2.0.4 --save

Once this is in place, we can go ahead and make a few changes to our server file. First up, we'll load in the library. I'll make a constant called socketIO and set it equal to the require statement for the socket.io library:

const path = require('path');const express = require('express');const socketIO = require('socket.io');

With this in place, we now need to integrate Socket.io into our existing web server. Currently, we use Express ...

Get Advanced Node.js Development 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.