https://github.com/pipedreamhq/node-sse-example
Process events from Pipedream SSE streams in Node.js
https://github.com/pipedreamhq/node-sse-example
Last synced: 7 months ago
JSON representation
Process events from Pipedream SSE streams in Node.js
- Host: GitHub
- URL: https://github.com/pipedreamhq/node-sse-example
- Owner: PipedreamHQ
- License: mit
- Created: 2020-03-09T23:28:52.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-26T06:38:00.000Z (over 3 years ago)
- Last Synced: 2025-06-07T10:41:54.586Z (7 months ago)
- Language: JavaScript
- Homepage: https://pipedream.com
- Size: 10.7 KB
- Stars: 4
- Watchers: 10
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Process events from Pipedream SSE streams in Node.js
## Prerequisites
- [Install the `pd` CLI](https://docs.pipedream.com/cli/install/)
- [Sign up for a Pipedream account](https://docs.pipedream.com/cli/login/#signing-up-for-pipedream-via-the-cli)
- [Create your first event source](https://github.com/PipedreamHQ/pipedream/blob/master/apps/http/README.md#quickstart)
## Quickstart
Clone this repo, `cd` into the cloned directory, and run
```bash
npm i
```
Then rename the `.env.example` file:
```bash
mv .example.env .env
```
This file contains placeholders for your Pipedream API key and SSE URL for your source. You can find your API key in your [Pipedream Account Settings](https://pipedream.com/settings/account), and get your SSE URL by running `pd list streams` and copying the URL under the **SSE** section. Add both to the `.env` file:
```text
PD_API_KEY=abc123
SSE_URL=https://rt.pipedream.com/sse/dc/dc_abc123/emits
```
Finally, run
```bash
node index.js
```
You'll see a confirmation that you're connected to the right URL, then the script will wait for you to send new events to your source:
```text
λ node index.js
Connected to https://rt.pipedream.com/sse/dc/dc_rmXuqV/emits. Listening for new events...
```
In another shell, trigger a new event in your source (for example, send an HTTP request to its endpoint — run `pd describe ` to get its endpoint URL), and the script should print it.
## Modify the code to process events in a custom way
This code in `index.js` processes the event:
```javascript
es.onmessage = event => {
console.log(event.data);
};
```
Just modify the code within this function to parse and process the event in whatever way you'd like.
## Questions?
Feel free to [reach out to the Pipedream team](https://docs.pipedream.com/support/) or raise an issue in this repo with any questions.