- Now, go back to your NodeJS project that was created in the first recipe. Let's download the node.js socket.io dependency:
~> npm install express socket.io --save
- Socket.io is also event-based and lets us create our custom event for everything we have, plus some native one for connections. Also, we've installed ExpressJS for configuration sake in order to create a socket.io server.
- Now after doing that, we need to configure our socket.io server using express. In this case, do as shown in the following code:
const express = require('express'); const app = express(); app.io = require('socket.io')(); // [*] Configuring our static files. app.use(express.static('public/')); // [*] Configuring Routes. app.get('/', (req, res) ...