Integrating Socket.IO with Express

So far, apart from sharing the same server, the Socket.IO and Express parts of our application are completely independent. While it's good that they are loosely coupled, some cross-cutting concerns may be relevant to both.

For example, both parts of our application should have a mutually consistent way of identifying the current user. This is especially important if they are to come together to provide a single coherent user experience.

First, let's extend our user middleware to provide the current user's name as well as their ID, by looking them up in the user service as given here src/middleware/users.js:

'use strict';

module.exports = (service) => { const uuid = require('uuid'); return function(req, res, next) ...

Get Learning Node.js for .NET Developers 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.