Adding an event listener for newLocationMessage

The last piece to the puzzle to really get all this working is to add an event listener for the newLocationMessage event. In index.js we can call socket.on to do just that. We're going to pass in our two arguments. First up is the event name we want to listen for, newLocationMessage, and the second and final argument is our function. This is going to get called with the message information once the event occurs:

socket.on('newLocationMessage', function (message) { 
 
}); 

Now that we have this, we can go ahead and start generating the DOM elements that we want to spit out to the user, and just like we did above, we're going to make a list item and we're going to add our anchor tag, our link inside ...

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.