{"library":"sse","title":"sse.js: Server-Sent Events for Node.js","type":"library","description":"The `sse` package (einaros/sse.js) provides a server-side implementation of the HTML5 Server-Sent Events (SSE) specification for Node.js applications. SSE enables a server to push data to web pages over HTTP, facilitating real-time communication without the overhead of WebSockets for unidirectional data flows. Currently at version `0.0.8`, this package is considered abandoned, with its last release dating back approximately eight years (published December 2017, but copyright 2011) and minimal activity on its GitHub repository. Its primary differentiator was offering a straightforward, low-level API to integrate SSE directly with Node.js's native HTTP server, abstracting the complexities of managing event streams and client connections. Given its age, it relies exclusively on CommonJS and is likely incompatible with modern Node.js versions and ES module adoption. Users seeking SSE functionality in current Node.js environments should consider actively maintained alternatives such as `@fastify/sse`, `sse-channel`, or `better-sse` due to potential compatibility, security, and feature limitations.","language":"javascript","status":"abandoned","last_verified":"Sat Apr 25","install":{"commands":["npm install sse"],"cli":null},"imports":["const SSE = require('sse');"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/einaros/sse.js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sse","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"var SSE = require('sse')\n  , http = require('http');\n\nvar server = http.createServer(function(req, res) {\n  res.writeHead(200, {'Content-Type': 'text/plain'});\n  res.end('okay');\n});\n\nserver.listen(8080, '127.0.0.1', function() {\n  console.log('Server listening on http://127.0.0.1:8080');\n  var sse = new SSE(server);\n  sse.on('connection', function(client) {\n    console.log('Client connected. Sending initial message...');\n    client.send('hi there!');\n\n    // Example: Send a message every 3 seconds\n    let counter = 0;\n    const interval = setInterval(() => {\n      client.send(`Message from server: ${counter++}`);\n    }, 3000);\n\n    client.on('close', () => {\n      console.log('Client disconnected.');\n      clearInterval(interval);\n    });\n  });\n});\n\n// Client-side JavaScript (for browser to connect):\n// var es = new EventSource(\"/sse\");\n// es.onmessage = function (event) {\n//   console.log(\"Received: \" + event.data);\n// };","lang":"javascript","description":"Sets up a basic Node.js HTTP server that integrates `sse.js` to handle Server-Sent Events. It sends an initial message upon client connection and then broadcasts periodic updates every three seconds, demonstrating unidirectional server-to-client communication.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}