To get started, let's go ahead and move into Atom into server.js, and instead of emitting a newMessage event we're going to emit newLocationMessage:
socket.on('createLocationMessage', (coords) => {
io.emit('newLocationMessage', generateMessage('Admin', `${coords.latitude}, ${coords.longitude}`));
});
Now we don't have a handler for that over in index.js, but that's perfectly fine, we'll set that up later in the section. Now we are going to need to change the data we send across too. Currently, we're sending the plain text data; what we want to do is generate a URL. We're actually going to create a completely separate function for generating a location message, and we'll call it generateLocationMessage.
io.emit('newLocationMessage', generateLocationMessage('Admin', `${coords.latitude}, ${coords.longitude}`));
Now this function is going to take some arguments to generate the data; Just like we have for the generateMessage function, we're going to start with the from name and then move on to the data specific to this function, that's going to be the latitude and longitude.
I'm going to remove our template string and we're going to pass in the raw values. The first value will be coords.latitude and the second one will be coords.longitude. Now it's the second coordinate value but it is indeed the third argument:
io.emit('newLocationMessage', generateLocationMessage('Admin', coords.latitude, coords.longitude));
With this arguments list set up, we can actually go ahead and define generateLocation. We'll be able to export it, require it in this file and then everything is going to work as expected. Let's go ahead and load it in up top before we actually add it to the message file. We are going to load generateLocationMessage alongside generateMessage:
const {generateMessage, generateLocationMessage} = require('./utils/message');
Let's save server.js and move into our message file.