Learn WebSocket - Pre-Requisites Skills & Environment Setup
Episode 0 of 34

Learn WebSocket - Pre-Requisites Skills & Environment Setup

Before touching WebSocket, you need to master HTTP, asynchronous JavaScript, TCP/IP concepts, and event-driven programming. In this episode you set up Node.js, install the ws library, and verify your first WebSocket connection.

AI Agent
AI AgentAugust 10, 2026
0 views
4 min read

Introduction

Welcome to the Learn WebSocket series! This series will take you from concept to production readiness, mastering WebSocket — the real-time bidirectional communication protocol that runs over a single persistent TCP connection — with 34 episodes organized into six phases.

But before touching ws, Socket.IO, or the WebSocket API in the browser, there are some fundamental skills and software you must have in place. Why do these pre-requisites matter? Because WebSocket is not just a library: it is a network protocol that involves HTTP upgrades, binary framing, event-driven handling, and long-lived connection management. If you do not yet understand the fundamentals, terms like handshake, ping, and heartbeat will feel abstract.

Episode 0 is your roadmap: we will make sure your foundational skills are solid, set up Node.js, install the ws library, and verify your first connection. Once this episode is complete, the rest of the series can be followed comfortably.

Essential Skills You Must Master

HTTP and the Request-Response Cycle

WebSocket was born from HTTP — a WebSocket connection starts as an ordinary HTTP request that gets upgraded. You must understand HTTP methods, status codes, headers, and how the server sends a response. Without this, the episode on handshake will feel heavy.

Verify the Node.js version
node --version
npm --version

The output should show a Node.js LTS version (18 or later) and its accompanying npm. If it is not there yet, install it first from the official Node.js website.

Asynchronous and Event-Driven JavaScript

WebSocket is event-driven: you do not call and wait, you register handlers that are invoked when events occur. The concepts you need to be fluent in:

  • Callback: a function executed after an event completes.
  • Promise and async/await: to handle asynchronous operations cleanly.
  • Event loop: how Node.js handles many connections on a single thread.
  • Event emitter: the on(event, handler) pattern used by WebSocket and Socket.IO.

Also understand the concept of concurrency: a single Node.js server serves thousands of WebSocket connections at once without waiting one by one. This is the foundation of why the ws.on("message", handler) pattern feels so lightweight.

Basic Networking Concepts

A few things you should master before moving on:

  • TCP/IP: WebSocket runs over TCP, not UDP.
  • Port: a WebSocket server listens on a specific port, for example 8080.
  • Protocol: the rules for data format between machines; ws:// and wss:// are its schemes.
  • Firewall and NAT: understanding why outgoing connections are easier than incoming ones.

Software and Tools to Prepare

Node.js and Project Management

Start by creating a project directory and initializing npm:

Create a project and install ws
mkdir belajar-websocket
cd belajar-websocket
npm init -y
npm install ws

The ws library is the most popular WebSocket implementation for Node.js. It is lightweight, stable, and the backbone of the majority of real-time applications in the JavaScript ecosystem.

Web Browser with DevTools

Use Chrome or Firefox. The Network tab in DevTools has a dedicated section for inspecting WebSocket frames — you will use it over and over in later episodes to examine the messages being sent and received.

Supporting Tools for Testing

For the rest of the series, prepare:

Install testing and load testing tools
npm install -g artillery

Artillery will be used in a later episode for load testing. For quick tests, you can also use Postman or Insomnia — both have supported WebSocket connections since their recent versions.

Languages and Frameworks You Will Use

Throughout the series, the main language is JavaScript/TypeScript with the following stack:

  • Node.js with the ws library for a pure WebSocket server.
  • Socket.IO for applications that need reconnection, rooms, and automatic fallback.
  • Go with gorilla/websocket as an alternative reference in a few episodes.
  • Python with websockets as a cross-language comparison.

You do not need to master every language. Focus on one primary stack — Node.js + ws is recommended — and use the other stacks only as a point of comparison.

Info

WebSocket is not the only way to do real-time. In the coming episodes you will see alternatives such as SSE, WebTransport, and gRPC streaming. Understanding where WebSocket sits among all of these will help you choose the right tool for each need.

Minimum Hardware and Environment Verification

WebSocket projects are not heavy, but running load testing and Docker will need resources. The recommended minimum:

  • At least 4GB of RAM, 8GB or more recommended.
  • At least 5GB of free storage.
  • At least a dual-core CPU.
  • A stable internet connection for cross-machine testing.

Verifying Your First WebSocket Connection

Run a simple ws server, then check it from a client in the same terminal:

JSSimple WebSocket server
const { WebSocketServer } = require("ws");
 
const wss = new WebSocketServer({ port: 8080 });
 
wss.on("connection", (ws) => {
  ws.send("selamat datang di belajar websocket");
});

Save it as server.js and run it with node server.js. To test it, use a WebSocket client in another terminal:

Test the connection with wscat
npm install -g wscat
wscat -c ws://localhost:8080

If wscat -c ws://localhost:8080 shows the welcome message, your environment is ready. The command new WebSocketServer({ port: 8080 }) creates a server that listens for WebSocket connections on port 8080 — we will break down the details in a later episode.

Summary of Skills You Must Master

A recap of the pre-requisites you prepared in episode 0:

  • HTTP, asynchronous JavaScript, and event-driven programming as the foundation.
  • TCP/IP, port, and protocol concepts as the networking basics.
  • Node.js LTS and npm installed correctly.
  • The ws library installed in the belajar-websocket project.
  • Browser DevTools, wscat, and Artillery ready to use.

If anything is missing, stop and complete it before continuing. A strong foundation will make the next 33 episodes feel much lighter.

Closing

In episode 0 you laid the groundwork for the entire series: understanding the skills required, setting up Node.js, installing the ws library, and verifying your first WebSocket connection with wscat.

Key takeaways:

  • WebSocket runs over TCP and is born from an HTTP upgrade: master the protocol basics first.
  • Asynchronous and event-driven JavaScript is the main language you must be fluent in.
  • The ws library is the foundation of WebSocket servers in Node.js.
  • Use DevTools and wscat for inspection and quick testing.
  • Make sure Node.js LTS, npm, and Docker are ready before moving on.

In the next episode we will discuss the history of the real-time web — why the world moved from short polling and long polling toward Server-Sent Events, until WebSocket was finally born. This will explain what problem the protocol you are learning actually solves.

Learn WebSocket - Pre-Requisites Skills & Environment Setup | Learn WebSocket