Greeting an individual user

To kick things off, we'll fill out the first call. This is a call to socket.emit, and this call will be responsible for greeting the individual users:

// socket.emit from Admin text Welcome to the chat appsocket.emit

We will still send an event of newMessage type and the exact same data from text and createdAt. The only difference here is that we'll be generating all the properties as opposed to getting some of them from the user as we did earlier. Let's get started with from. This one will be from Admin. Any time we send a message via the server, we'll call Admin and the text will be our little message, Welcome to the chat app. Next, we'll add createdAt, which will be set equal to new Date by calling the Date().getTime ...

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.