/node-sse-example

Process events from Pipedream SSE streams in Node.js

Primary LanguageJavaScriptMIT LicenseMIT

pipedream

Process events from Pipedream SSE streams in Node.js

Prerequisites

Quickstart

Clone this repo, cd into the cloned directory, and run

npm i

Then rename the .env.example file:

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, and get your SSE URL by running pd list streams and copying the URL under the SSE section. Add both to the .env file:

PD_API_KEY=abc123
SSE_URL=https://rt.pipedream.com/sse/dc/dc_abc123/emits

Finally, run

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:

λ 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 <source> 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:

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 or raise an issue in this repo with any questions.