WebSocket + Node.js + Express — Step by step tutorial using Typescript

Jonny Fox
Factory Mind
Published in
5 min readMay 23, 2017

--

Update

Checkout my new Angular WebSocket client article 😙.

You could be interested in my article about realtime and schemaless database (Cloud Firestore) and Angular -> Step by step tutorial and “CUD operations, transactions and batch writes deep dive”.

This is a quick step by step tutorial about WebSocket, Node/Express and Typescript. The full source code provided in these examples is lovely hosted by Github.

WebSocket is a communication protocol that provides a full-duplex communication channels over a single TCP connection established between a web browser (client) and a web server (this take place through the “classic HTTP mechanism” of handshaking, implemented using request/response headers).

This allows the server to send content to the browser without being called by the client, pushing data through the opened connection, defining ws and wss as URI schemes used respectively for unencrypted and encrypted connections.

In this tutorial we are going to use ws, a simple client/server library for Node.js that helps us to manage all the stuff under the protocol.

I choose this library instead of the well known Socket.IO because today the WebSocket protocol is natively…

--

--

Factory Mind
Factory Mind

Published in Factory Mind

Factory Mind is a young and dynamic cooperative consisting of a team of passionate developers, with a kick for computer science, technology and innovation. The main goal of the cooperative is striving to become a center of excellence and a reference point for software development

Jonny Fox
Jonny Fox

Responses (20)