A TypeScript library for building Nostr protocol WebSocket clients and servers, providing robust connection management with automatic reconnection, heartbeat monitoring, message queueing, and comprehensive error handling. Version 0.4.1 is the current stable release, actively maintained with a monthly release cadence. Key differentiators include dual ESM/CommonJS module support, full Nostr NIP implementation (NIP-01, 02, 11, 15, 16, 20, 42), type-safe handlers, and integration with nostr-crypto-utils. Supports both browser and Node.js environments with secure WebSocket (WSS) connections and Vitest test suite.
npm install nostr-websocket-utilsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a Nostr WebSocket client and server with the library, including connection options and message handlers.
Update your message handler to be async: handlers: { message: async (msg) => { ... } }Replace onMessage with handlers.message in the options object.
Use CommonJS require() in Node.js <18: const { NostrWSClient } = require('nostr-websocket-utils');If using a custom logger, ensure it has info, warn, error, debug methods.
Change import { NostrWSClient } from 'nostr-websocket-utils' (instead of import NostrWSClient from ...)Import NostrWSError from 'nostr-websocket-utils' directly instead of 'nostr-websocket-utils/errors'
Use const { NostrWSClient } = require('nostr-websocket-utils'); then new NostrWSClient(...)Upgrade bundler or use CommonJS (require) instead of ESM import
Ensure messages are arrays (e.g., ['EVENT', event]) or use the type-safe send methods