npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

websocket-close-codes

v1.0.0

Published

TypeScript library for WebSocket connection close codes based on RFC 6455

Readme

websocket-close-codes

npm version License

TypeScript library for WebSocket connection close codes based on RFC 6455 and MDN Close Event.

This package provides a strongly-typed enum for standard WebSocket close codes, making your WebSocket handling code more readable and less prone to magic number errors.

Installation

npm i websocket-close-codes

Usage

Import the CloseCode enum and use it to handle or send WebSocket close events.

import { CloseCode } from 'websocket-close-codes';

// Example: closing a connection
socket.close(CloseCode.NORMAL_CLOSURE, 'Work complete');

// Example: handling a close event
socket.addEventListener('close', (event) => {
  switch (event.code) {
    case CloseCode.NORMAL_CLOSURE:
      console.log('Clean exit');
      break;
    case CloseCode.GOING_AWAY:
      console.log('Server is going down or client navigated away');
      break;
    case CloseCode.PROTOCOL_ERROR:
      console.error('Protocol error occurred');
      break;
    default:
      console.log(`Closed with code: ${event.code}`);
  }
});

Available Codes

The CloseCode enum includes standard codes defined in RFC 6455:

| Code | Name | Description | | ---- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 1000 | NORMAL_CLOSURE | Indicates a normal closure, meaning that the purpose for which the connection was established has been fulfilled. | | 1001 | GOING_AWAY | Indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page. | | 1002 | PROTOCOL_ERROR | Indicates that an endpoint is terminating the connection due to a protocol error. | | 1003 | UNSUPPORTED_DATA | Indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message). | | 1004 | RESERVED | Reserved. The specific meaning might be defined in the future. | | 1005 | NO_STATUS_RECEIVED | Reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that no status code was actually present. | | 1006 | ABNORMAL_CLOSURE | Reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g., without sending or receiving a Close control frame. | | 1007 | INVALID_FRAME_PAYLOAD_DATA | Indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message). | | 1008 | POLICY_VIOLATION | Indicates that an endpoint is terminating the connection because it has received a message that violates its policy. This is a generic status code that can be returned when there is no other more suitable status code (e.g., 1003 or 1009) or if there is a need to hide specific details about the policy. | | 1009 | MESSAGE_TOO_BIG | Indicates that an endpoint is terminating the connection because it has received a message that is too big for it to process. | | 1010 | MISSING_EXTENSION | Indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. The list of extensions that are needed SHOULD appear in the /reason/ part of the Close frame. Note that this status code is not used by the server, because it can fail the WebSocket handshake instead. | | 1011 | INTERNAL_ERROR | Indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request. | | 1012 | SERVICE_RESTART | The server is terminating the connection because it is restarting. | | 1013 | TRY_AGAIN_LATER | The server is terminating the connection due to a temporary condition, e.g., it is overloaded and is casting off some of its clients. | | 1014 | BAD_GATEWAY | The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code. | | 1015 | TLS_HANDSHAKE | Reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified). |

License

MIT © Robert Kłódka