Nodemon

Alternatively, you may want to use a module called nodemon to automatically do this whenever any changes are made.

Run the following inside of your Terminal:

# Install nodemon globally$ npm install nodemon -g

We can then run:

# Listen for any changes to our server.js file and restart the server$ nodemon server.js

Great! Let's go back to our MessageForm component and create the sendMessage function:

methods: { sendMessage() {   this.socket.emit('chatMessage', {     username: this.username,     message: this.message,   }); },},

At this point hitting Send doesn't add the message to an array yet, but it does give us the sent message inside of our ...

Get Vue.js 2 Design Patterns and Best Practices 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.