This project demonstrates how to use Redis streams as a source for an EventEmitter in Node.js. It uses the example of weather data that might have been gathered from a weather station using a software-defined radio. However, the source is weather data doesn't matter for this example as it only looks at the contents of a Redis stream.
- Node.js: Ensure you have Node.js installed on your system.
- Redis: A running Redis instance is required, as this project utilizes Redis Streams.
git clone https://github.com/guyroyse/stream-event-emitter.git
cd stream-event-emitter
npm installBy default, the app connects to Redis at localhost:6379. If your Redis instance is hosted elsewhere or requires authentication, update the Redis connection settings in main.ts. Details on how to do this can be found in the Node Redis docs.
Start the application with:
npm run devThe app will begin listening to a Redis stream for weather events and emit them. You'll see a few show up the are hard-coded in main.ts. You can add some manually to Redis by using Redis Insight and running commands like:
> xadd weather:stream * temperature 78
> xadd weather:stream * humidity 62
> xadd weather:stream * temperature 77 humidity 63 windSpeed 12I hope you find this example useful!