This is a simple real-time application demonstrating the Pub-Sub design pattern using Node.js, Express.js, and Socket.IO.
-
Make sure that you have Node.js and npm installed on your system. If not, you can download and install them from the official Node.js website.
-
Clone this repository to your local machine:
git clone https://github.com/delvoid/pubsub-basic.git
- Navigate into the project folder and install the dependencies:
pnpm install
- Start the server:
pnpm dev
- Open a terminal and run the client:
npx ts-node src/client.ts
- The client will prompt you to enter commands. You can publish or subscribe to events using the following commands:
- To subscribe to an event, type
subscribe [event]
. For example,subscribe event1
. - To publish a message to an event, type
publish [event] [message]
. For example,publish event1 Hello, world!
.
Multiple clients can subscribe to the same event and will all receive any messages published to that event. A client can subscribe to multiple events.
Basic demo
The tester.ts script is designed to automate testing of the Pub-Sub application. Running npx ts-node src/tester.ts initiates a series of automated event subscriptions and publications, allowing developers to validate application functionality without manual input.
npx tst-node src/tester.ts