{"id":48654,"library":"nanosocket","title":"nanosocket","description":"A tiny WebSocket client (~1KB bundled) with built-in reconnection and exponential backoff, offering callback/promise/stream-based message handling via emitterify. Version 1.1.0 is the current stable release. It is a lightweight alternative to heavier WebSocket libraries, focusing on minimal overhead and reconnection handling. The library works in browser and Node.js environments, but requires emitterify for stream/callback functionality.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","websocket","client"],"install":[{"cmd":"npm install nanosocket","lang":"bash","label":"npm"},{"cmd":"yarn add nanosocket","lang":"bash","label":"yarn"},{"cmd":"pnpm add nanosocket","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for event-based stream and callback handling (on('recv'), on('connected'), etc.)","package":"emitterify","optional":false}],"imports":[{"note":"Default export only; CJS require returns the default as module.exports.","wrong":"const { nanosocket } = require('nanosocket')","symbol":"nanosocket","correct":"import nanosocket from 'nanosocket'"},{"note":"Use on('recv') for incoming messages, not 'message'. send() returns a promise.","wrong":"const socket = nanosocket(); socket.on('message', ...) (no such method)","symbol":"send/on (via nanosocket)","correct":"import nanosocket from 'nanosocket'\nconst socket = nanosocket('wss://example.com')\nsocket.send('msg').then(...)\nsocket.on('recv').map(d => ...)"},{"note":"No official type definitions; may need custom .d.ts if using TypeScript.","wrong":"","symbol":"default (type)","correct":"import type nanosocket from 'nanosocket'  (if using with TypeScript)"}],"quickstart":{"code":"import nanosocket from 'nanosocket'\n\nconst socket = nanosocket('wss://echo.websocket.org')\n\nsocket.on('recv').map(d => console.log('received:', d))\nsocket.on('connected').map(d => console.log('connected'))\nsocket.on('disconnected').map(d => console.log('disconnected'))\n\nsocket.send('Hello').then(() => console.log('sent'))\n\nsetTimeout(() => socket.close(), 5000)","lang":"javascript","description":"Creates a WebSocket connection, logs incoming messages, connection events, and sends a message."},"warnings":[{"fix":"Use socket.on('recv') instead of socket.on('message').","message":"Message events use 'recv' instead of standard 'message'.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use socket.on('connected') and socket.on('disconnected') as provided by the library.","message":"The 'connected' and 'disconnected' events are not part of standard WebSocket API.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Await the promise to ensure message is sent before proceeding.","message":"send() returns a promise that resolves when the message is actually sent, not when queued.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install @types/nanosocket or create a custom declaration file.","message":"No built-in TypeScript types; may cause type errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.0':23 '1kb':6 'altern':33 'backoff':15 'browser':49 'built':10 'built-in':9 'bundl':7 'callback/promise/stream-based':17 'client':5,61 'current':26 'emitterifi':21,55 'environ':52 'exponenti':14 'focus':38 'function':58 'handl':19,44 'heavier':35 'javascript':59 'librari':37,46 'lightweight':32 'messag':18 'minim':40 'nanosocket':1 'node.js':51 'offer':16 'overhead':41 'reconnect':12,43 'releas':28 'requir':54 'stabl':27 'stream/callback':57 'tini':3 'version':22 'via':20 'websocket':4,36,60 'work':47","created_at":"2026-06-07T16:57:45.265470+00:00","updated_at":"2026-06-07T16:57:45.265470+00:00","problems":[{"fix":"Ensure emitterify is installed: npm install emitterify. Check import path.","cause":"Missing emitterify dependency or incorrect import.","error":"TypeError: socket.on is not a function"},{"fix":"Ensure emitterify is loaded and socket is initialized properly.","cause":"Using socket.on('recv') without emitterify or in wrong context.","error":"TypeError: Cannot read property 'map' of undefined"},{"fix":"Verify the WebSocket server URL and ensure it's accessible.","cause":"WebSocket server is not running or URL is incorrect.","error":"WebSocket connection to 'wss://...' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"nanosocket","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}