{"id":18064,"library":"sse","title":"sse.js: Server-Sent Events for Node.js","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.","status":"abandoned","version":"0.0.8","language":"javascript","source_language":"en","source_url":"git://github.com/einaros/sse.js","tags":["javascript","real-time","server-sent-events","html5","sse","messaging"],"install":[{"cmd":"npm install sse","lang":"bash","label":"npm"},{"cmd":"yarn add sse","lang":"bash","label":"yarn"},{"cmd":"pnpm add sse","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and explicitly designed for older Node.js runtimes (v0.4.0+). Attempting to use ES module import syntax (`import ... from 'sse'`) will result in a runtime error. It does not provide a default export, nor does it support named exports via ES modules.","wrong":"import { SSE } from 'sse';\nimport SSE from 'sse';","symbol":"SSE","correct":"const SSE = require('sse');"}],"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."},"warnings":[{"fix":"Avoid using this package in new projects. For existing projects, consider migrating to actively maintained SSE libraries compatible with modern Node.js, such as `@fastify/sse`, `sse-channel`, or `better-sse`.","message":"This package is designed for very old Node.js versions (>=0.4.0) and is largely incompatible with modern Node.js runtimes due to significant API changes and lack of maintenance. Direct usage may lead to runtime errors or unexpected behavior on current Node.js versions.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Do not use this package in production environments. Migrate to a well-maintained and actively developed SSE solution that addresses modern security standards.","message":"The `sse` package is unmaintained and marked as inactive/discontinued. This poses significant security risks as it will not receive updates for vulnerabilities or bug fixes. Its codebase has not been audited for modern security concerns.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure `require('sse')` is used in CommonJS contexts. For projects using ES modules, a wrapper might be necessary, but migration to a modern, ESM-compatible SSE library is strongly recommended.","message":"The package exclusively supports CommonJS (`require()`) syntax. It does not provide ES module exports and will cause runtime errors if `import` statements are used, making integration into modern JavaScript projects cumbersome.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install sse` to ensure the package is available. If using ES modules, rewrite your import to `const SSE = require('sse');` in a CommonJS-compatible file, or switch to a modern SSE library with ESM support.","cause":"This error typically occurs if the package has not been installed (`npm install sse`) or if `import { SSE } from 'sse'` is used in an ES module environment when the package only offers CommonJS exports.","error":"Error: Cannot find module 'sse'"},{"fix":"Verify that `http.createServer` correctly returns a server instance and that the server is properly listening before passing it to `new SSE(server)`. Given the package's age, fundamental incompatibilities with modern Node.js `http` module APIs are likely; consider migrating to an alternative SSE library.","cause":"This error can occur if the `SSE` constructor is called with an invalid or `undefined` HTTP server object, or if Node.js HTTP server APIs have changed significantly since the package's last update.","error":"TypeError: Cannot read properties of undefined (reading 'on')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}