Integrate the utility function into our application

The first step in this process will be to import the function we just created. I'm going to do that creating a constant in server.js. We'll use ES6 destructuring to grab generateMessage, and we're going to grab it off of a call to require. Now we're requiring a local file in a different directory. We're going to start with ./, go into the utils directory since we're currently in the server directory, and then grab the file message by specifying it:

const socketIO = require('socket.io');const {generateMessage} = require('./utils/message');

Now we have access to generateMessage, and instead of creating these objects we can call generateMessage. In socket.emit, we're going to replace Welcome ...

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.