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

@cocreate/server-mesh

v1.7.0

Published

Decentralized, event-driven P2P server mesh and transport fabric for CoCreate Server. Optimizes multi-tenant cluster concurrency with dynamic, tenant-isolated WebSocket data tunnels.

Downloads

1,110

Readme

@cocreate/server-mesh

A high-performance, self-healing, peer-to-peer (P2P) encrypted transport fabric built for distributed cluster orchestration, real-time tenant routing, and inter-node event synchronization across the CoCreate ecosystem.


Documentation

For complete API references, deployment guides, and architecture documentation, visit the CoCreate Server Mesh documentation.

Table of Contents


Overview

@cocreate/server-mesh serves as the real-time inter-server transport plane for @cocreate/server. It establishes zero-trust, mutual P2P encrypted WebSocket tunnels between cluster nodes, enabling seamless multi-tenant data propagation, worker thread relays, and distributed cluster command execution.

Designed as a pure transport fabric, @cocreate/server-mesh blindly routes and emits network payloads as standard EventEmitter events across the cluster without introducing business-logic overhead.


Key Features

  • Zero-Trust Ephemeral TLS: Automatically generates temporary TLS credentials for secure node-to-node communication over the mesh network.
  • Polymorphic Target Directives: Unicast, multicast, broadcast, worker-specific, or tenant-aware routing using a unified payload format.
  • Cryptographic Traceability: Automatically stamps every outgoing frame with a unique crypto.randomUUID() identifier for distributed tracing and replay protection.
  • Tenant Isolation: Dynamically tracks tenant-to-worker and tenant-to-server mappings so messages are only delivered to nodes actively serving an organization.
  • Self-Healing Reconnection: Uses exponential backoff with randomized jitter to prevent reconnection storms after network interruptions.
  • Cluster IPC Integration: Transparently bridges Node.js Primary and Worker processes while extending communication across distributed servers.
  • EventEmitter API: Receive mesh messages using familiar Node.js event listeners.

Architecture & Message Pipeline

When a payload is dispatched through @cocreate/server-mesh, the routing engine evaluates execution context (Primary vs Worker), determines the target destination, and forwards the payload through IPC or encrypted peer connections.

$$ \text{Worker Thread} \xrightarrow{\text{IPC}} \text{Primary Process} \xrightarrow{\text{Route Resolution}} \begin{cases} \text{Local Workers} \ \text{Remote Peer Servers} \end{cases} $$

Worker Context

Worker processes:

  • Send outbound messages through native process.send()
  • Receive inbound mesh traffic through IPC
  • Never establish direct peer connections

Primary Context

The Primary process:

  • Hosts the secure mesh WebSocket server
  • Maintains encrypted peer connections
  • Tracks tenant routing information
  • Routes messages between workers and remote servers

Installation

NPM

npm install @cocreate/server-mesh

Yarn

yarn add @cocreate/server-mesh

Note

@cocreate/server-mesh integrates directly with @cocreate/server, but it can also be initialized independently.


Quick Start

Initialize

import CoCreateServer from "@cocreate/server";
import ServerMesh from "@cocreate/server-mesh";

await ServerMesh.init(CoCreateServer);

Send a Message

Unicast to a single server:

ServerMesh.send({
	method: "cache.flush",
	server: "srv_64f8a1bc90d1",
	data: {
		cache: "users"
	}
});

Multicast to multiple servers:

ServerMesh.send({
	method: "worker.task",
	server: ["srv_64f8a1bc90d1", "srv_90e3b2ac81f4"],
	worker: 2,
	data: {
		taskId: 1042
	}
});

Broadcast to every node:

ServerMesh.send({
	broadcast: true,
	method: "reload.configuration"
});

Listen for Messages

ServerMesh.on("cache.flush", (message) => {
	console.log(message.data);
});

Routing Directives & Targeting Matrix

| Target | Payload | Description | | --- | --- | --- | | Single Server | { server: "srv1" } | Routes only to the specified server. | | Multiple Servers | { server: ["srv1","srv2"] } | Sends to every listed server. | | Worker | { server: "srv1", worker: 2 } | Routes to a specific worker on the target server. | | Local Workers | { worker: [1,3] } | Sends only to selected local workers. | | Broadcast | { broadcast: true } | Delivers to every connected server and local worker. |


Tenant-Aware Routing Protocols

The mesh minimizes unnecessary network traffic by maintaining live organization routing maps.

Client Connect
        │
        ▼
mesh.registerOrg
        │
        ▼
Map Organization → Worker
        │
        ▼
Client Disconnect
        │
        ▼
60 Second Grace Timer
        │
        ▼
mesh.deregisterOrg
        │
        ▼
mesh.orgDeleted Broadcast

Organization Events

| Event | Description | | --- | --- | | mesh.registerOrg | Registers a worker serving an organization. | | mesh.deregisterOrg | Removes a worker's organization mapping after all connections close. | | mesh.orgAdded | Broadcast to peer servers when an organization becomes active. | | mesh.orgDeleted | Broadcast when an organization is no longer active on a server. | | mesh.orgData | Routes organization-specific payloads only to subscribed servers and workers. |


Self-Healing & Reconnection Logic

When peer servers disconnect, reconnection attempts use exponential backoff combined with randomized jitter to prevent synchronized reconnect storms.

$$ T_{delay}

\min\left(30000,, 1000\times1.5^{attempt} \right) + random(500,4500) $$

Connections automatically retry until:

  • the peer becomes available,
  • the server shuts down,
  • or the connection is intentionally closed.

Programmatic API Reference

ServerMesh.init(server)

Initializes the mesh networking layer.

await ServerMesh.init(server);

ServerMesh.send(payload)

Routes a payload across the cluster.

ServerMesh.send({
	method: "custom.command",
	server: "srv123",
	data: {
		key: "value"
	}
});

ServerMesh.close()

Gracefully closes all mesh connections and releases resources.

await ServerMesh.close();

Events

ServerMesh.on("mesh.orgAdded", handler);

ServerMesh.on("mesh.orgDeleted", handler);

ServerMesh.on("mesh.orgData", handler);

ServerMesh.on("mesh.raw_message", handler);

Security & TLS Specification

  • Encrypted Transport: All peer communication occurs over mutually authenticated encrypted WebSocket connections.
  • Dedicated Mesh Port: Mesh traffic is isolated from public HTTP and HTTPS traffic.
  • Ephemeral Certificates: Temporary TLS certificates are generated during startup and automatically replaced on restart.
  • Server Authentication: Incoming peers must successfully complete server identity validation before joining the mesh.
  • UUID Tracing: Every transmitted frame receives a unique identifier for distributed tracing and replay protection.

Environment Variables

| Variable | Default | Description | | --- | --- | --- | | MESH_PORT | 8090 | Port used for mesh communication. | | CLUSTER_SECRET | — | Shared secret used during mesh authentication. | | SERVER_ID | Auto Generated | Persistent identifier for the current server node. |


Announcements

Release notes, performance improvements, protocol updates, and networking enhancements are published with every release. Follow the repository to stay informed about new features and compatibility changes.


Roadmap

Upcoming enhancements include:

  • Native QUIC / HTTP/3 transport
  • Adaptive routing based on latency measurements
  • Automatic peer discovery across local networks
  • Streaming binary frame optimizations
  • Dynamic topology-aware routing

How to Contribute

We welcome pull requests, bug reports, documentation improvements, performance optimizations, and security reviews.

Please review the project's CONTRIBUTING.md before submitting changes, and use the GitHub Issues page to report bugs or request new features.

Community feedback helps prioritize development and improve the platform.


About

@cocreate/server-mesh is designed, built, and maintained by the CoCreate Developer Experience Team.

It serves as the distributed communication backbone of the CoCreate ecosystem, providing secure, low-latency messaging between clustered servers.

For questions, architecture discussions, or deployment guidance, visit the project's GitHub Discussions or join the CoCreate community.


License

This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license.

Open Source

For open-source projects and non-commercial use, this software is available under the AGPLv3. See the LICENSE file for the complete license text.

Commercial

Organizations requiring proprietary use may obtain a commercial license from CoCreate.