O'Reilly logo

Socket.IO Cookbook by Tyson Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling server-side validation

When we write data to a database, it is important to perform validation on the server side to ensure that the data is in the type and format that we expect it to be in. In this recipe, we will demonstrate how we can emit data to the server and emit messages back if there is a success or an error.

Getting ready

We will use promises to handle success and error states. Depending on your version of Node, you may need to install the promise module with npm install promise –save. Promises are a feature of ES6, so they will eventually be native in Node.

How to do it…

To handle validation on the server side, follow these steps:

  1. First, we will create a method for performing some validation on the server side. Typically, your ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required