{"id":49714,"library":"websocket-event-codes","title":"WebSocket Event Codes","description":"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).","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/FenrirWillow/websocket-event-codes","tags":["javascript","websocket","status","codes"],"install":[{"cmd":"npm install websocket-event-codes","lang":"bash","label":"npm"},{"cmd":"yarn add websocket-event-codes","lang":"bash","label":"yarn"},{"cmd":"pnpm add websocket-event-codes","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package does not support ESM imports; use require().","wrong":"import WebSocketEventCodes from 'websocket-event-codes';","symbol":"WebSocketEventCodes","correct":"const WebSocketEventCodes = require('websocket-event-codes');"},{"note":"Destructuring from require() works; ESM import will fail.","wrong":"import { NORMAL_CLOSURE } from 'websocket-event-codes';","symbol":"NORMAL_CLOSURE","correct":"const { NORMAL_CLOSURE } = require('websocket-event-codes');"},{"note":"Access as property of the default export.","wrong":null,"symbol":"WebSocketEventCodes.NORMAL_CLOSURE","correct":"const codes = require('websocket-event-codes');\nconsole.log(codes.NORMAL_CLOSURE);"}],"quickstart":{"code":"const WebSocketEventCodes = require('websocket-event-codes');\n\n// Close a WebSocket with a normal closure\nws.close(WebSocketEventCodes.NORMAL_CLOSURE, 'OK');\n\n// Check if a status code is defined\nif (WebSocketEventCodes.GOING_AWAY) {\n  console.log('Status code 1001: GOING_AWAY');\n}\n\n// List all codes\nconsole.log(WebSocketEventCodes);","lang":"javascript","description":"Shows how to require the module, use a specific code to close a WebSocket, and log all codes."},"warnings":[{"fix":"Use require() instead of import. For TypeScript, manually declare the module or use `const WebSocketEventCodes = require('websocket-event-codes');` with `@types/node`.","message":"The package is CommonJS-only and does not provide an ESM entry or type definitions.","severity":"gotcha","affected_versions":"<=1.1.0"},{"fix":"Do not attempt to add or modify status codes on the exported object.","message":"The object is frozen (Object.freeze) so its properties cannot be modified at runtime.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only use codes 1000-1004, 1007-1014 for sending. Reserved codes (1005, 1006, 1015) are for internal use.","message":"Some status codes like 1005 and 1006 are reserved and should not be sent in a close frame.","severity":"gotcha","affected_versions":"*"},{"fix":"Consider manually adding missing codes or switching to a maintained alternative.","message":"The package has not been updated since 2020; newer WebSocket RFC status codes (e.g., 1016-1017) are not included.","severity":"deprecated","affected_versions":"<=1.1.0"}],"env_vars":null,"search_vec":"'1.1.0':19 '1000':50 'agnost':28 'browser':74 'bundler':77 'closur':49 'code':3,15,46,81 'commonj':67 'constant':17 'depend':7,64 'dependency-fre':6 'e.g':47 'enumer':12 'environ':75 'event':2 'export':35 'free':8 'http':58 'http-status':57 'human':40 'human-read':39 'inspir':53 'javascript':78 'latest':22 'librari':26,32 'map':38 'modul':10,60 'name':42 'node.js':9,72 'normal':48 'numer':44 'object':37 'provid':11 'readabl':41 'releas':24 'similar':56 'simpli':34 'small':5 'stabl':23 'status':14,45,59,80 'suitabl':69 'support':66 'version':18 'via':76 'websocket':1,13,31,79","created_at":"2026-06-07T17:03:14.354573+00:00","updated_at":"2026-06-07T17:03:14.354573+00:00","problems":[{"fix":"Ensure Node.js version supports require() for CJS. Use `const codes = require('websocket-event-codes');`","cause":"Attempting to use `require()` on a package that is ESM-only, but websocket-event-codes is CJS-only; this error might occur if misconfigured.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported."},{"fix":"Use CommonJS `require()` instead of `import`.","cause":"Trying to import the package using `import` without transpilation.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Double-check the require path and the property name. Use: `const codes = require('websocket-event-codes');` then `codes.NORMAL_CLOSURE`.","cause":"The package was not properly required or the variable name is misspelled.","error":"TypeError: codes.NORMAL_CLOSURE is undefined"}],"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":"https://github.com/FenrirWillow/websocket-event-codes#readme","github":"https://github.com/FenrirWillow/websocket-event-codes","docs":null,"changelog":null,"pypi":null,"npm":"websocket-event-codes","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"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}}