Emitting custom message

The next thing that we want to do is emit a message. We're going to emit a message from the admin to everybody, kind of like we did up above. We greeted the user and we told all other users that someone joined, right here we're going to emit('newMessage'), and we're going to call generateMessage like we've done in the past. We're going to pass in those two arguments, the first one is Admin. This is going to be an admin message, and the second one can be a template string, we're going to inject the user's name, user.name, and then we're going to say that user has left:

io.to(user.room).emit('updateUserList', users.getUserList(user.room)); io.to(user.room).emit('newMessage', generateMessage('Admin', `${user.name} has ...

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.