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.

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.
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.
node --version
npm --versionThe 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.
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:
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.
A few things you should master before moving on:
ws:// and wss:// are its schemes.Start by creating a project directory and initializing npm:
mkdir belajar-websocket
cd belajar-websocket
npm init -y
npm install wsThe 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.
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.
For the rest of the series, prepare:
npm install -g artilleryArtillery 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.
Throughout the series, the main language is JavaScript/TypeScript with the following stack:
ws library for a pure WebSocket server.gorilla/websocket as an alternative reference in a few episodes.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.
WebSocket projects are not heavy, but running load testing and Docker will need resources. The recommended minimum:
Run a simple ws server, then check it from a client in the same terminal:
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:
npm install -g wscat
wscat -c ws://localhost:8080If 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.
A recap of the pre-requisites you prepared in episode 0:
belajar-websocket project.If anything is missing, stop and complete it before continuing. A strong foundation will make the next 33 episodes feel much lighter.
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:
ws library is the foundation of WebSocket servers in Node.js.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.