Registry / storage / websocket-event-codes

websocket-event-codes

JSON →
library1.1.0jsnpmunverified

A small, dependency-free Node.js module providing enumerated WebSocket status codes as constants. Version 1.1.0 is the latest stable release. This library is agnostic to any WebSocket library and simply exports an object mapping human-readable names to numeric status codes (e.g., NORMAL_CLOSURE: 1000). It is inspired by the similar http-status module. It has no dependencies and supports CommonJS only. Suitable for both Node.js and browser environments (via bundler).

npm install websocket-event-codes
INSTALL
IMPORT
SIG · WEBSOCKET-EVENT-CO
W
websocket-event-codes
storagejavascriptv1.1.0
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.

WebSocketEventCodes
const WebSocketEventCodes = require('websocket-event-codes');
import WebSocketEventCodes from 'websocket-event-codes';
This package does not support ESM imports; use require().
NORMAL_CLOSURE
const { NORMAL_CLOSURE } = require('websocket-event-codes');
import { NORMAL_CLOSURE } from 'websocket-event-codes';
Destructuring from require() works; ESM import will fail.
WebSocketEventCodes.NORMAL_CLOSURE
const codes = require('websocket-event-codes'); console.log(codes.NORMAL_CLOSURE);
Access as property of the default export.

Shows how to require the module, use a specific code to close a WebSocket, and log all codes.

const WebSocketEventCodes = require('websocket-event-codes'); // Close a WebSocket with a normal closure ws.close(WebSocketEventCodes.NORMAL_CLOSURE, 'OK'); // Check if a status code is defined if (WebSocketEventCodes.GOING_AWAY) { console.log('Status code 1001: GOING_AWAY'); } // List all codes console.log(WebSocketEventCodes);
Debug
Known issues
gotchaThe package is CommonJS-only and does not provide an ESM entry or type definitions.
fix
Use require() instead of import. For TypeScript, manually declare the module or use `const WebSocketEventCodes = require('websocket-event-codes');` with `@types/node`.
affects: <=1.1.0
gotchaThe object is frozen (Object.freeze) so its properties cannot be modified at runtime.
fix
Do not attempt to add or modify status codes on the exported object.
affects: >=1.0.0
gotchaSome status codes like 1005 and 1006 are reserved and should not be sent in a close frame.
fix
Only use codes 1000-1004, 1007-1014 for sending. Reserved codes (1005, 1006, 1015) are for internal use.
affects: *
deprecatedThe package has not been updated since 2020; newer WebSocket RFC status codes (e.g., 1016-1017) are not included.
fix
Consider manually adding missing codes or switching to a maintained alternative.
affects: <=1.1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
Attempting to use `require()` on a package that is ESM-only, but websocket-event-codes is CJS-only; this error might occur if misconfigured.
fix
Ensure Node.js version supports require() for CJS. Use `const codes = require('websocket-event-codes');`
SyntaxError: Unexpected token 'export'
Trying to import the package using `import` without transpilation.
fix
Use CommonJS `require()` instead of `import`.
TypeError: codes.NORMAL_CLOSURE is undefined
The package was not properly required or the variable name is misspelled.
fix
Double-check the require path and the property name. Use: `const codes = require('websocket-event-codes');` then `codes.NORMAL_CLOSURE`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
36
OpenAI (training)
3
Bingbot
1
Resources
websocket-event-codes — npm install websocket-event-codes · libregistry