The first thing we're going to do is tweak our message.js file. Currently inside message.js, we generate timestamps using new Date().getTime. We're going to switch over to Moment, not because it changes anything, I just want to be consistent with using Moment everywhere we use time. This is going to make it a lot easier to maintain and figure out what's going on. At the top of the message.js, I'm going to make a variable called moment setting it equal to require('moment'):
var moment = require('moment');
var generateMessage = (from, text) => {
return {
from,
text,
createAt: new Date().getTime()
};
};
And we're going to go ahead and replace the createdAt property with calls to valueOf. What I would like you to do is go ahead and do just that, call moment, call the valueOf method in generateMessage and in generateLocationMessage, and then go ahead and run the test suite and make sure both tests pass.
The first thing we need to do is tweak the createdAt property for generateMessage. We're going to call moment, call valueOf getting back the timestamp, and we're going to do the same thing for generateLocationMessage:
var moment = require('moment');
var generateMessage = (from, text) => {
return {
from,
text,
createdAt: moment().valueOf()
};
};
var generateLocationMessage = (from, latitude, longitude) => {
return {
from,
url: `https://www.google.com/maps?q=${latitude},${longitude}`,
createdAt: moment().valueOf()
}
};
Now we can go ahead and save message.js. Head over into the Terminal and run our test suite using the following command:
npm test
We get two tests and they both still pass, which means the value we're getting back is indeed a number as our tests assert:

Now that we have Moment integrated on the server, we're going to go ahead and do the same thing on the client.