Socket.IO and WebSockts

Currently I am experimenting with a data-intensive application built using web technologies. The biggest challenge is to reflect in UI real-time changes to the data stored on the server.

First implementation

I implemented long polling where the client polls the server, requesting new information. The server receives the request from the client, keeps it open and responds once new data is available. This implementation is suitable for small projects but can become a problem for high scalable applications with numerous clients and frequent changes to data.

Second implementation

The second approach is to implement bidirectional communication between server and client and allow the server to push notification to the client only when data changes. In this context one can use WebSocket-s.
WebSocket ( is a computer communications protocol, providing full-duplex communication channels over a single TCP.

A convenient abstraction around the WebSocket protocol is Socket.IO library/module (


Socket.IO enables real-time, bidirectional and event-based communication. It works on every platform, browser or device, focusing equally on reliability and speed.

In the context of Node.js, Socket.IO provides a consistent interface both in the browser and on the server for performing bidirectional communications.

Socket.IO provides an abstraction over the various methods used to maintain an active connection between a browser and a server. It will use WebSocket where the protocol is supported, and will transparently fall back to several other techniques in cases where WebSocket is not yet supported or the firewall introduces some limitations.

Below you can find a working example for demonstrating the bidirectional communication between Client and Server using Socket.IO.

The code is available also on Git:


Open the Terminal and create the project structure:

$mkdir socket-io-demo
$cd socket-io-demo
$npm init

Install the Socket.IO module:

$npm install

Add the server side code:

$nano index.js

Add the client code:

$nano index.html

Start the server:

$node index.js

Open the Browser and navigate to this URL: http://localhost:4200/


Node Version Manager (nvm)


I have recently installed Ubuntu 18.04.1 LTS. Still I haven’t given up on Windows as the default OS and I am using VirtualBox ( hypervisor in order to create the underlying virtual machine.

My goal in the next few months is to experiment with several cool technologies:

  • Node.js
  • MongoDB
  • Docker
  • and Linux

As you all know Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. It actually consists of three different parts:

  • libuv: a high performance, cross-platform evented I/O library
  • V8: Google’s JavaScript engine (also used in Chrome)
  • js & C++ code: developed specifically for the Node platform

Installing Node.js on Linux

There are several ways to install Node.js on Linux :

1. Directly download it from the official website (

2. Use Node Version Manager or ‘nvm’ (

nvm is a tool that allows one to manage multiple Node.js versions installations in a Linux or Mac environment.

In order to install nvm, open the terminal an run the following commands:

$ wget -qO- | bash

$ command -v nvm

Close your current terminal, open a new terminal, and nvm command should be available.

After nvm has been installed and ready to use, try to list all installed Node.js versions:

$ nvm ls

node -> stable (-> N/A) (default)
iojs -> N/A (default)

In order to install the latest version of Node.js (for me is 10.14.2):

$ nvm install v10.14.2

Once again list the installed versions of Node.js:

$ nvm ls
-> v10.14.2
default -> v10.14.2
node -> stable (-> v10.14.2) (default)
stable -> 10.14 (-> v10.14.2) (default)

You can double check the current version of Node.js:

$ node -v

And of course npm (Node Package Manager) has been installed:

$ npm -v

To open the Node.js REPL (Read-Eval-Print-Loop):

$ node
> console.log("Hello REPL!");
Hello REPL!

In order to leave the Node.js REPL hit ^C (CTRL+C).

There are several other useful nvm commands. For example one can chose to install an older version of Node.js (v10.14.0) and use it as default:

$ nvm install v10.14.0
$ nvm alias default v10.14.0
$ nvm ls
-> v10.14.0
default -> v10.14.0
node -> stable (-> v10.14.2) (default)
stable -> 10.14 (-> v10.14.2) (default)

And now the default version is v10.14.0.
Note that versions v10.14.0 exist side by side and can be used interchangeably.