Now, in order to listen to a custom event, we are still going to use socket.on; although, instead of specifying the name of one of the built-in events, we'll provide the first argument inside quotes as the name of our custom event. In this case, that name is going to be newEmail:
socket.on('newEmail');
Now, the second argument for socket.on is the same as the second argument for the built-in event listeners. We'll provide a function, and this function is going to get called when the event fires:
socket.on('newEmail', function () {
});
For now, all we're going to do inside the function is use console.log to print a little message, New email:
socket.on('newEmail', function () {
console.log('New email');
});
This will print inside of the web developer console every time the client hears this event coming across the pipeline. Now that we have the listener in place for newEmail, let's go ahead and emit this event inside server.js.