Lesson 24 — Pub/sub with topics
Messages by topic
A message broker sits between parts of a system. Publishers send a message to a named topic; subscribers listen to the topics they care about. Neither side knows the other exists. Tools like Redis Pub/Sub, RabbitMQ and Kafka work this way.
b.sub("news", (m) => console.log(m));
b.pub("news", "hello");
Note: this playground runs JavaScript in your browser, not in real Node, so Node-only tools (like fs or http) are not available. The exercise is a small plain-JS simulation of the Node idea.
Why it matters: decoupled services can be added or removed without changing each other.
Add an unsub(topic, fn) method, unsubscribe the first news listener, and publish again.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Node.js Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Node.js Foundations books — check the publication year so the examples match current versions.
Search Amazon →