April 2018
Beginner
226 pages
4h 47m
English
The WebSocket implementation is wrapped and handled with an amazing library called Socket.IO. It is not just a library, but a framework that provides so many more features than just a library. Moving on, let's install Socket.IO using the following command:
npm install socket.io --save
Now, we need to render the template in the browser upon a request to the node server. To do so, add the following snippet to our app.js:
const templateData = require('./index.html');const server = require('http').createServer((req, res) => { res.setHeader('content-type', 'text/html'); res.end(templateData);});const io = require('socket.io')(server);io.on('connection', function(client) { client.on('disconnect', function() { console.log('user ...Read now
Unlock full access