https://github.com/kenfdev/eventemitter-poc
https://github.com/kenfdev/eventemitter-poc
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kenfdev/eventemitter-poc
- Owner: kenfdev
- License: mit
- Created: 2022-08-17T00:33:57.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T19:07:09.000Z (over 1 year ago)
- Last Synced: 2024-10-29T19:09:18.030Z (over 1 year ago)
- Language: TypeScript
- Size: 483 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# In-Memory Event Driven Architecture with EventEmitter
This app is a PoC to show how you can publish/subscribe to events using EventEmitter in Node.js. The example publishes a domain event from the use case layer (*) and the published event is handled by a different use case.
*Note: Although it is generally said that domain events should be published from Aggregates(the domain layer), this example publishes domain events from the use case layer for simplicity
## Architecture

## Try yourself
```sh
npm install
npm test
npm run dev
```
The server runs on http://localhost:3030. Create a POST request to `http://localhost:3030/users`.
```json
{
"username": "johndoe",
"email": "johndoe@test.test"
}
```
You should receive a response similar to the one below:
```json
{
"id": "7294d859-9beb-49c9-b96f-0f77338dcab5",
"email": "johndoe@test.test",
"username": "johndoe"
}
```
Also, you should see a log that indicates a message was sent in the console output:
```sh
send {
"from": "noreply@test.test",
"to": "johndoe@test.test",
"subject": "Welcome!",
"text": "Welcome aboard!"
}
```