An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

![pipedream](https://i.ibb.co/hB42XLK/github2.png)




# 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.