{"id":20590,"library":"susie","title":"SuSiE","description":"Server-Sent Events plugin for hapi.js, allowing event streaming via h.event() with support for individual event objects and readable streams. Current stable version: 3.0.0. Works with Node >=8.9.0. Key differentiator: tight hapi integration, auto-stringification of objects, and automatic handling of reconnect via a built-in 'end' event. Ideal for real-time updates like notifications or live feeds.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/mtharrison/susie","tags":["javascript","sse","hapi","realtime","server-sent","streaming"],"install":[{"cmd":"npm install susie","lang":"bash","label":"npm"},{"cmd":"yarn add susie","lang":"bash","label":"yarn"},{"cmd":"pnpm add susie","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin registration and toolkit decoration","package":"hapi","optional":false}],"imports":[{"note":"Requires CommonJS, as susie is a hapi plugin. No default export for ESM.","wrong":"const { susie } = require('susie');","symbol":"default","correct":"const susie = require('susie');\nawait server.register(susie);"},{"note":"h.event() is not a standalone import; it's added to the hapi response toolkit after registering the plugin.","wrong":"import { event } from 'susie';","symbol":"h.event()","correct":"// Decorated on toolkit after registration\nhandler: function (request, h) {\n    return h.event({ data: 'hello' });\n}"},{"note":"Use the standard hapi plugin pattern. As of hapi v17+, registration must be awaited.","wrong":"server.register({ register: susie, options: {} });","symbol":"plugin registration","correct":"await server.register({ plugin: require('susie'), options: {} });"}],"quickstart":{"code":"const Hapi = require('@hapi/hapi');\nconst susie = require('susie');\n\nconst start = async () => {\n    const server = Hapi.server({ port: 3000 });\n    await server.register(susie);\n\n    server.route({\n        method: 'GET',\n        path: '/events',\n        handler: (request, h) => {\n            const response = h.event({ id: 1, data: 'hello' });\n            let count = 1;\n            const interval = setInterval(() => {\n                count++;\n                h.event({ id: count, data: `message ${count}` });\n                if (count >= 5) {\n                    clearInterval(interval);\n                    h.event(null); // sends 'end' event and closes\n                }\n            }, 1000);\n            return response;\n        }\n    });\n\n    await server.start();\n    console.log('Server running on', server.info.uri);\n};\n\nstart();","lang":"javascript","description":"Registers the susie plugin and creates an SSE endpoint that sends 5 events with 1-second intervals, then closes the connection with an 'end' event."},"warnings":[{"fix":"On the client, listen for the 'end' event and call source.close().","message":"Calling h.event(null) sends a final event named 'end' before closing the response. The client must listen for this event and close the EventSource to prevent automatic reconnect.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"On the client, use JSON.parse(event.data) if the data originated from an object.","message":"Object mode streams: When passing a stream in objectMode, each chunk is JSON-stringified. Ensure client parses the data field as JSON if needed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to @hapi/hapi v17+ and use async/await for server registration.","message":"v3 drops support for hapi v16 and earlier; requires @hapi/hapi v17+ (Node >=8.9.0).","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Use require('susie') directly in server.register().","message":"Using require('susie') returns a plugin object; the old require('susie').plugin pattern is deprecated but still works.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure await server.register(require('susie')); is called before defining routes.","cause":"susie plugin not registered before route handler or incorrect registration.","error":"Error: h.event is not a function"},{"fix":"Use const susie = require('susie'); and pass it directly to server.register.","cause":"Using named import syntax with require or import on susie.","error":"TypeError: Cannot destructure property 'susie' of ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}