Registry / messaging / easy-websocket

easy-websocket

JSON →
library0.2.1jsnpmunverified

A simple WebSocket server library for Node.js that provides both high-level connection handling and low-level frame manipulation. Current stable version is 0.2.1. It allows custom authentication via an optional auth callback and supports both string and binary data frames. Compared to alternatives like ws or Socket.IO, easy-websocket offers a minimal API but lacks advanced features like reconnection, automatic JSON parsing, and client-side support.

npm install easy-websocket
INSTALL
IMPORT
SIG · EASY-WEBSOCKET
E
easy-websocket
messagingjavascriptv0.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (factory function)
var websocket = require('easy-websocket');
import websocket from 'easy-websocket';
This package does not support ESM imports; use CommonJS require.
WebSocket protocol handler
var websocketlib = require('easy-websocket/websocket');
var websocketlib = require('easy-websocket').websocket;
The low-level WebSocket protocol handler is exported via a separate path, not as a property of the main module.
authentication override
var WebSocket = require('easy-websocket'); var ws = new WebSocket(server); ws.auth = function(req) { return false; };
Authentication is configured by setting the auth property on the WebSocket server instance before connections.

Creates a simple HTTP server that serves an HTML file and upgrades connections to WebSocket using easy-websocket.

var http = require('http'); var fs = require('fs'); var websocket = require('easy-websocket'); var server = http.createServer(function(req, res) { fs.readFile('./index.html', function(err, data) { res.end(data); }); }); websocket(server) .on('connect', function(ws) { ws.on('data', function(obj) { console.log(obj.type); ws.send('hello world'); }); }); server.listen(3000);
Debug
Known issues
gotchaThe npm package is named 'easy-websocket' but the GitHub repository does not appear to have recent updates or releases.
fix
Consider using a more actively maintained WebSocket library like 'ws' or 'socket.io'.
affects: >=0.0.0
gotchaThe main module uses CommonJS and does not support ESM imports. Attempting to import with ES modules will fail.
fix
Use require() instead of import.
affects: >=0.0.0
deprecatedThe documentation example shows 'require('easy-websocket/ws')' which is not a valid path. The correct low-level path is 'easy-websocket/websocket'.
fix
Use require('easy-websocket/websocket') for low-level WebSocket handling.
affects: >=0.0.0
gotchaThe package does not include TypeScript type definitions.
fix
Use @types/easy-websocket if available, or define your own types.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'easy-websocket/ws'
Incorrect path for low-level WebSocket protocol handler; the documentation lists 'ws' but the correct path is 'websocket'.
fix
Change to require('easy-websocket/websocket')
TypeError: websocket is not a function
Attempting to use ES module import syntax with a CommonJS package.
fix
Use const websocket = require('easy-websocket');
ReferenceError: WebSocket is not defined
This library is intended for server-side Node.js, not browser environments. The `WebSocket` global in the example is the browser's native WebSocket.
fix
In browser code, use the native WebSocket API directly. For server code, ensure you are using Node.js and the correct require path.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
26
OpenAI (training)
1
Resources
easy-websocket — npm install easy-websocket · libregistry