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

kcpjs

v1.0.12

Published

kcpjs = kcpgo_to_js(kcp)

Readme

kcpjs

npm version License: MIT

A pure JavaScript implementation of KCP (KCP Protocol) with FEC (Forward Error Correction) and encryption support.


Features

  • Pure JavaScript Implementation: No native dependencies
  • FEC Support: Reed-Solomon error correction
  • Encryption Support: AES-GCM encryption
  • TypeScript Support: Full type definitions
  • High Performance: Optimized for real-time communication

Compared to node-kcp-x, this implementation adds two key features:

  1. FEC (Forward Error Correction): Improves reliability over unreliable networks
  2. Encryption: Secure data transmission

Installation

npm install kcpjs

Quick Start

Example 1: Echo Server

ts-node examples/echo.ts

Example 2: Client-Server Communication

# Terminal 1
ts-node examples/server.ts

# Terminal 2
ts-node examples/client.ts

API Reference

Server

ListenWithOptions(options)

Creates a KCP server listener

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | port | number | Server port | | block | CryptBlock \| undefined | Encryption module | | dataShards | number | FEC data shards | | parityShards | number | FEC parity shards | | callback | (session: Session) => void | Client connection callback |

Client

DialWithOptions(options)

Creates a KCP client connection

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | host | string | Server address | | port | number | Server port | | conv | number | Session ID | | block | CryptBlock \| undefined | Encryption module | | dataShards | number | FEC data shards | | parityShards | number | FEC parity shards |


Usage Examples

Basic Server

import { ListenWithOptions } from 'kcpjs';
import { AesBlock } from 'kcpjs/crypt';
import * as crypto from 'crypto';

// Encryption setup
const algorithm: crypto.CipherGCMTypes = 'aes-128-gcm';
const key = crypto.randomBytes(128 / 8);
const iv = crypto.randomBytes(12);

// FEC configuration
const dataShards = 4;
const parityShards = 1;

const server = ListenWithOptions({
    port: 22333,
    block: new AesBlock(algorithm, key, iv),
    dataShards,
    parityShards,
    callback: (session) => {
        console.log('New client connected');
        
        session.on('recv', (data: Buffer) => {
            // Echo back received data
            session.write(data);
        });
    },
});

Basic Client

import { DialWithOptions } from 'kcpjs';
import { AesBlock } from 'kcpjs/crypt';
import * as crypto from 'crypto';

// Same encryption setup as server
const algorithm: crypto.CipherGCMTypes = 'aes-128-gcm';
const key = crypto.randomBytes(128 / 8);
const iv = crypto.randomBytes(12);

const dataShards = 4;
const parityShards = 1;

const session = DialWithOptions({
    host: '127.0.0.1',
    port: 22333,
    conv: 255,
    block: new AesBlock(algorithm, key, iv),
    dataShards,
    parityShards,
});

session.on('recv', (data: Buffer) => {
    console.log('Received:', data.toString());
});

// Send data
setInterval(() => {
    const message = Buffer.from('Hello from client');
    session.write(message);
}, 1000);

Configuration

FEC (Forward Error Correction)

FEC helps recover lost packets without retransmission

  • dataShards: Number of data shards
  • parityShards: Number of parity shards
  • Set either to 0 to disable FEC

Window Limits

session.setWindowSize(sndwnd, rcvwnd) controls the KCP send and receive windows. Values above IKCP_WND_SND_MAX or IKCP_WND_RCV_MAX are clamped to the exported hard limits to keep per-session memory bounded.

Encryption

Supports AES-GCM encryption

  • algorithm: Cipher algorithm (e.g., 'aes-128-gcm')
  • key: Encryption key
  • iv: Initialization vector
  • Set any parameter to empty to disable encryption

Development

Build

yarn build

Format

yarn format

Lint

yarn lint

License

MIT License


Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Related Projects

  • kcp-go - Original KCP implementation in Go
  • node-kcp-x - Basic Node.js KCP implementation