Server Sent Event Support [GOT CREATED]

Hi it would be really good to have Server-Sent Event supported in N8N

var EventSource = require('EventSource')

const webhookProxyUrl = "https://smee.io/07c5PdfR5dduiWxb"; // replace with your own Webhook Proxy URL
const source = new EventSource(webhookProxyUrl);
source.onmessage = event => {
  const webhookEvent = JSON.parse(event.data);
  console.log("Test");
  console.log(webhookEvent);
};

Can you please explain a little bit more. What exactly do you want to do? Do you want to send SSE or do you want to receive them?

I am trying to access Server sent events so that I can access data behind a firewall, I was trying to create a custom n8n node the would allow me to use EventSource to listen to events that are forwarded as Json, I was find it very difficult to debug if the events was getting fired off, I did try to use console.log but I couldn’t see the logs in dev console, any help would be much appreciated

Ok, now I understand. When you say a custom node you mean you tried to create a custom Trigger-Node or do you mean you tried within a Function-Node? Because the later would not work.

Yes I mean a custom trigger node.

Yes, that should work fine and should not be too complicated. It should be almost identical to the Interval-Node.

About console.log. The messages would not show up in the “dev-console” of your browser, they would show up in the terminal in which you run n8n from.

Ah ok, that makes sense, thanks for your help, FYI this tool is really useful

You are welcome. If you have any other problems or questions simply get back to me. Once you have the Node working you can simply create a pull-request. I will then check, merge and release with the next version. If you have problems and do not get it up and running simply tell me then I can have a look myself.

Always very happy to hear when n8n is useful for somebody!

OK thanks for your help

Hi @jan , I couldn’t get SSE to work due to my lack of js knowledge, any chance if you could add the implementation, thanks in advance

Sure! Will have a look and release with the next version.

1 Like

Just released [email protected] with the SSE-Trigger Node.
Happy new year 2020!

Very much appreciated , happy new year

HI @jan I have been trying to test SSE but looks like the event does not get automatically trigged even if I send the request manually, I can see the request when I manually press excute button then trigger off an Server event.

{
  "nodes": [
    {
      "parameters": {
        "url": "https://smee.io/07c5PdfR5uoiWxb"
      },
      "name": "SSE Trigger",
      "type": "n8n-nodes-base.sseTrigger",
      "typeVersion": 1,
      "position": [
        560,
        400
      ],
      "notes": "Get events from github"
    }
  ],
  "connections": {}
}

hm before I released the nodes I tested it and for me, it worked perfectly fine.

Be aware that the node works similarly as the webhook node. So that it only listens ongoing in production mode and only for a single event when testing. So if you want to test it. You either press the “play-button” directly on the “SSE Trigger” node or on a node afterward which is connected to it. You should then see that the “SSE Trigger” node is active, as the arrows are rotating. That means it is waiting for a Server Sent Event. As soon as it receives one it will then display you the data in the UI and then stop listening again.

Here the comment about how the webhook node works:

ok thanks for your help

So it works now fine?

yep thats working, cheers

1 Like