Creating the server

The first thing that we need to do is create a WebSocket server to relay messages between our clients. Find a suitable project folder, open your terminal/command line, and run the following:

npm init

This will create the basic Node.js project structure. You can enter whatever values you see fit:

{
  "name": "ionic-chat-server",
  "version": "1.0.0",
  "description": "A websocket server for chatting.",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "csvan",
  "license": "MIT"
}

Now, let's install the dependencies that we will need. Run the following command:

npm install socket.io

This will install socket.io, which is all we will need in order to get our server running.

Next, create the ...

Get Learning Node.js for Mobile Application 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.