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

@plantae-tech/socket-event

v3.0.3

Published

A TCP socket library for event-driven communication.

Downloads

367

Readme

🔌 @plantae-tech/socket-event

A lightweight library for event-driven communication over TCP sockets, enabling structured messaging between servers and clients using a familiar event-based API.

npm version license

Features

  • Familiar on / emit API built on top of Node.js EventEmitter
  • Base64-encoded JSON framing — works over any TCP stream
  • Server broadcasts to all connected clients
  • Automatic connection and disconnection tracking
  • Zero runtime dependencies

Installation

npm install @plantae-tech/socket-event

Quick Start

Server

import { Server } from '@plantae-tech/socket-event';

const server = new Server(1337);

server.on('listening', () => {
    console.log('Server listening on port 1337');
});

server.on('connection', (client) => {
    console.log('Client connected');

    client.on('message', (text: string) => {
        console.log('Received:', text);
        client.emit('reply', `Echo: ${text}`);
    });
});

server.on('disconnection', (client) => {
    console.log('Client disconnected');
});

server.start();

Client

import { Client } from '@plantae-tech/socket-event';

const client = new Client('localhost', 1337);

client.on('connect', () => {
    console.log('Connected to server');
    client.emit('message', 'Hello!');
});

client.on('reply', (text: string) => {
    console.log('Server says:', text);
});

client.on('close', () => {
    console.log('Disconnected');
});

Examples

Broadcasting to all clients

const server = new Server(1337);

server.on('connection', (client) => {
    client.on('chat', (message: { nickname: string; text: string }) => {
        // Forward to every connected client
        server.broadcast('chat', message);
    });
});

server.start();

Sending structured data

Events can carry any JSON-serializable data:

// Client sends an object
client.emit('player:move', { x: 10, y: 20, timestamp: Date.now() });

// Server receives it
socket.on('player:move', (data: { x: number; y: number; timestamp: number }) => {
    console.log(data.x, data.y, data.timestamp);
});

Graceful shutdown

process.on('SIGINT', () => {
    server.broadcast('shutdown', 'Server is shutting down');
    server.close(); // Disconnects all clients and closes the server
});

API

Server

| Method | Description | |--------|-------------| | new Server(port) | Create a server bound to port | | start() | Start listening for connections | | close() | Close the server and disconnect all clients | | broadcast(event, data?) | Emit an event to every connected client |

Events: listening, connection, disconnection, error

Client

| Method | Description | |--------|-------------| | new Client(host, port) | Connect to a server | | emit(event, data?) | Send an event to the server | | disconnect() | Gracefully close the connection (returns Promise) | | destroy() | Immediately destroy the socket |

Events: connect, close, end, error, plus any custom events from the server

Socket

Base class used by both Client and server-side client sockets. Extends EventEmitter.

Protocol

Messages are framed as newline-delimited Base64-encoded JSON:

{"name":"event-name","data":{"key":"value"}}  →  base64  →  <base64>\n

Each line is one event. The receiver splits on \n, decodes each chunk from Base64, and parses the JSON to extract name and data.