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

socket-ts

v1.0.0

Published

Socket.io server with Redis adapter in TypeScript

Readme

Socket.IO Server with Redis Adapter

This project is a TypeScript version of a Socket.IO server using Redis Adapter with the official Redis library.

Features

  • Built with TypeScript
  • Socket.IO with Redis Adapter to support multiple instances
  • Uses the official Redis library (node-redis) instead of IORedis
  • Supports both Redis Single and Redis Cluster modes
  • Can switch between single and cluster modes at runtime
  • JWT authentication
  • MVC architecture
  • Docker and Docker Compose for deployment

Installation

Installing Dependencies

npm install

Environment Configuration

Copy the .env.example file to .env and configure the environment variables:

cp .env.example .env

Redis Configuration

The application supports two Redis modes:

  1. Single mode - Connect to a single Redis server:
REDIS_MODE=single
REDIS_URI=redis://localhost:6379
REDIS_PASSWORD=your_redis_password
  1. Cluster mode - Connect to a Redis Cluster:
REDIS_MODE=cluster
REDIS_PASSWORD=your_redis_password
REDIS_CLUSTER_NODES=127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6382

Switching Between Redis Modes

You can switch between Redis single and cluster modes at runtime by calling the API:

# View current configuration
curl http://localhost:3000/redis/config

# Switch to single mode
curl -X POST http://localhost:3000/redis/config \
  -H "Content-Type: application/json" \
  -d '{"mode":"single","uri":"redis://localhost:6379","password":"your_password"}'

# Switch to cluster mode
curl -X POST http://localhost:3000/redis/config \
  -H "Content-Type: application/json" \
  -d '{"mode":"cluster","clusterNodes":["127.0.0.1:6380","127.0.0.1:6381","127.0.0.1:6382"],"password":"your_password"}'

Development

Run in Development Mode

npm run dev

Build Project

npm run build

Run Built Application

npm start

Deployment with Docker

Build and Run with Docker Compose

docker-compose up -d

View Logs

docker-compose logs -f

API

  • GET /: Returns server status
  • GET /health: Check server health
  • GET /redis/config: Get current Redis configuration
  • POST /redis/config: Update Redis configuration

Socket.IO Events

Client to Server

  • subscribe: Subscribe to receive messages from a room
  • unsubscribe: Unsubscribe from receiving messages
  • reaction: Send a reaction to a room
  • get_online_users: Get the list of online users in a room

Server to Client

  • history: Returns message history when client subscribes
  • online_users: Returns list of online users in a room
  • user_joined: Notification when a user joins a room
  • user_left: Notification when a user leaves a room
  • on_reaction: Sends reactions to all clients in a room

Directory Structure

socket-ts/
├── src/
│   ├── config/           # Application configuration
│   ├── controllers/      # Application logic
│   ├── interfaces/       # Type definitions
│   ├── middleware/       # Middleware
│   ├── models/           # Models
│   ├── routes/           # Router
│   ├── services/         # Services
│   ├── utils/            # Utility functions
│   └── index.ts          # Application entry point
├── docker/               # Docker configurations
├── Dockerfile            # Docker build file
├── docker-compose.yml    # Docker Compose configuration
├── .env.example          # Example environment variables
├── package.json          # Dependencies and scripts
└── tsconfig.json         # TypeScript configuration

Test Tools

Redis Emitter Test Tool

A command-line tool for testing Socket.io with Redis adapter. This tool allows you to:

  • Send messages to specific rooms
  • Simulate users joining/leaving rooms
  • Send reactions to messages
  • Test custom events

To use the tool:

cd test-tools
npm install
npm start

See the test-tools/README.md for more details.