{"id":21579337,"url":"https://github.com/manuel-di-iorio/sse-node","last_synced_at":"2025-10-28T14:42:18.352Z","repository":{"id":93222038,"uuid":"57365782","full_name":"manuel-di-iorio/sse-node","owner":"manuel-di-iorio","description":"Server-sent events for Node.js","archived":false,"fork":false,"pushed_at":"2022-04-17T06:58:08.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-20T15:09:31.228Z","etag":null,"topics":["http","nodejs","sse"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manuel-di-iorio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-04-29T07:44:38.000Z","updated_at":"2022-04-17T06:58:11.000Z","dependencies_parsed_at":"2023-04-01T04:34:09.585Z","dependency_job_id":null,"html_url":"https://github.com/manuel-di-iorio/sse-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/manuel-di-iorio/sse-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuel-di-iorio%2Fsse-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuel-di-iorio%2Fsse-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuel-di-iorio%2Fsse-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuel-di-iorio%2Fsse-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manuel-di-iorio","download_url":"https://codeload.github.com/manuel-di-iorio/sse-node/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuel-di-iorio%2Fsse-node/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260340088,"owners_count":22994420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","nodejs","sse"],"created_at":"2024-11-24T13:13:00.580Z","updated_at":"2025-10-28T14:42:18.347Z","avatar_url":"https://github.com/manuel-di-iorio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NOTICE: Unmaintained repository\n\n# Server-sent events for Node.js\nSend data to the clients in real time with SSE technology\n\n### Install it with:\n  \n    npm install sse-node\n    or\n    git clone https://github.com/manuel-di-iorio/sse-node.git\n    \n### Example with HTTP server:\n\n```javascript\nconst SSE = require(\"sse-node\"),\n      http = require(\"http\");\n\nhttp.createServer((req, res) =\u003e {\n    if (req.url !== \"/sse\") return res.end();\n    \n    // This will open a SSE connection on the request and will send the message to the client.\n    // On disconnection, a message is logged.\n    const client = SSE(req, res);\n    client.send(\"Hello world!\");\n    client.onClose(() =\u003e console.log(\"Bye client!\"));\n})\n.listen(80);\n```\n\n### Example with Express.js:\n\n```javascript\nconst SSE = require(\"sse-node\"),\n      app = require(\"express\")();\n\napp.get(\"/sse\", (req, res) =\u003e {\n    const client = SSE(req, res);\n    client.send(\"Hello world!\");\n    client.onClose(() =\u003e console.log(\"Bye client!\"));\n});\n\napp.listen(80);\n```\n\n### Example with Koa.js:\n\n```javascript\nconst SSE = require(\"sse-node\"),\n      app = require(\"koa\")();\n\napp.use(function *(next) { // Also compatible with Koa 2, see the doc for the changes\n    if (this.url !== \"/sse\") return;\n    \n    const client = SSE(this.req, this.res);\n    client.send(\"Hello world!\");\n    client.onClose(() =\u003e console.log(\"Bye client!\"));\n});\n\napp.listen(80);\n```\n\n---\n**On the client side, just connect with javascript to the server with:**\n```javascript\nvar es = new EventSource(\"/sse\");\nes.onmessage = function(ev) {\n    alert(ev.data); //will output 'Hello world!'\n};\n\n// You can also listen other events with .addEventListener()\n```\n\n---\n## API\n\n```javascript\nSSE(request, response, [options])\n```\n\n    Wrap a HTTP request/response object with this function to create a SSE connection for the incoming request.\n    \n    *Options* can have the following properties:\n    \n        `ping`: When to send a ping to the client each X seconds (by default is disabled)\n        `retry`: After how many millisecons to retry the connection (by default is 3000)\n        `padding`: Some older browsers require to write a 2KB padding when the SSE connection starts.\n          By default this is disabled.\n\nThis function returns a object with the following methods:\n```javascript\n.send(data, [event])\n```\n    *Data* can be anything. Objects will get serialized\n\n    *Event*: You can send a message to a specific event and listen to it on the client side\n      with ev.addEventListener(\"eventName\", function). By default, all messages are sent to the 'message' event\n\n---\n```javascript\n.onClose([callback])\n```\n    When the client disconnects, will call the specified callback. The param is optional because this function\n      also clears the ping interval when set.\n    \n    \n### Test with:\n\n    node test\nThen navigate with your browser to `http://localhost:9090` and open the javascript console\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanuel-di-iorio%2Fsse-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanuel-di-iorio%2Fsse-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanuel-di-iorio%2Fsse-node/lists"}