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

@jnode/server-ws

v1.0.3

Published

Official WebSocket support for JNS.

Readme

@jnode/server-ws

Official WebSocket support for JNS.

Installation

npm i @jnode/server-ws

Quick start

Import

const { createServer, routerConstructors: r, handlerConstructors: h } = require('@jnode/server');
const { routerConstructors: wsr, handlerConstructors: wsh } = require('@jnode/server-ws');

Start an echo WebSocket server

const server = createServer(
  r.Path(null, {
    // Check if the request is a WebSocket upgrade request
    '/chat': wsr.IsWS(
      // If it is, handle with WS handler
      wsh.WS((conn) => {
        console.log('New connection!');

        conn.on('message', (data) => {
          conn.send(`Echo: ${data}`);
        });
      }),
      // If not, respond with a plain text error
      h.Text('WebSocket upgrade required.', { statusCode: 426 })
    )
  })
);

server.listen(8080);

How it works?

@jnode/server-ws provides a seamless way to integrate WebSockets into your JNS application using the standard router-handler pattern.

  1. Use IsWSRouter to detect WebSocket upgrade requests based on HTTP headers (Upgrade, Connection, Sec-WebSocket-Key, etc.).
  2. Use WSHandler to perform the handshake (HTTP 101) and upgrade the connection.
  3. Once upgraded, you receive a <WSConnection> object to manage the full-duplex communication.

Reference

Routers

Router: IsWSRouter(isWS, isNotWS)

  • isWS router | handler-extended The router or handler to use if the request is a valid WebSocket upgrade request.
  • isNotWS router | handler-extended The router or handler to use if the request is NOT a WebSocket upgrade request.

Detects if the incoming request is a WebSocket handshake. It checks if the method is GET, the Upgrade header is websocket, and the Sec-WebSocket-Version is 13.

Handlers

Handler: WSHandler(cb[, options])

Handles the WebSocket handshake. If the request headers are invalid, it throws a 426 Upgrade Required error. Otherwise, it sends the 101 Switching Protocols response, flushes the headers, and invokes the callback with a <WSConnection> instance.

Integration with @jnode/server

When using these routers and handlers, the standard env and ctx objects are passed through the routing process as usual.

If ctx.finalizeLog is a function (commonly used by logging middleware), WSHandler will call it immediately after the handshake headers are flushed to ensure the upgrade request is logged before the connection switches protocols.