UNPKG

nuc-node-event-test

Version:
35 lines (26 loc) 1.28 kB
# Sample Usage: node-event This folder contains two sample Express apps demonstrating how to use the `nodeEvent` client to publish and subscribe to events via a central event server (expected to be running at `localhost:8080`). ## Structure - `publisher/`: Publishes events to the event server when a POST request is made. - `subscriber/`: Subscribes to events from the event server and logs them to the console. ## Prerequisites - The event server (Socket.IO server) must be running at `localhost:8080`. - Install dependencies in the project root: `npm install` ## Running the Apps ### 1. Start the Publisher ``` node sample/publisher/index.js ``` The publisher will listen on [http://localhost:3001](http://localhost:3001). Send a POST request to publish an event: ``` curl -X POST http://localhost:3001/send -H "Content-Type: application/json" -d '{"type":"test","payload":{"msg":"hello"}}' ``` ### 2. Start the Subscriber ``` node sample/subscriber/index.js ``` The subscriber will listen on [http://localhost:3002](http://localhost:3002) and log any received `test` events. ## What Happens? - When you POST to `/send` on the publisher, it emits a `test` event to the event server. - The subscriber, which is subscribed to `test` events, receives and logs the payload.