Installation
PubSubJS is distributed as multiple packages. Install only what you need.
Core Package
Section titled “Core Package”The core package is required for all PubSubJS applications:
# Using bun (recommended)bun add @pubsubjs/core
# Using npmnpm install @pubsubjs/core
# Using yarnyarn add @pubsubjs/core
# Using pnpmpnpm add @pubsubjs/coreSchema Validation
Section titled “Schema Validation”PubSubJS supports any Standard Schema compatible validation library. Install your preferred library:
# Zod (recommended)bun add zod
# Valibot (smaller bundle size)bun add valibot
# ArkTypebun add arktypeTransport Packages
Section titled “Transport Packages”Install the transport(s) you need:
WebSocket Transport
Section titled “WebSocket Transport”For real-time browser-server communication:
bun add @pubsubjs/transport-websocketRedis Transport
Section titled “Redis Transport”For distributed systems and microservices:
bun add @pubsubjs/transport-redisSSE Transport
Section titled “SSE Transport”For server-to-client streaming:
bun add @pubsubjs/transport-sseReact Integration
Section titled “React Integration”For React applications:
bun add @pubsubjs/reactPeer Dependencies
Section titled “Peer Dependencies”Some packages have peer dependencies:
| Package | Peer Dependencies |
|---|---|
@pubsubjs/core | zod or valibot (optional) |
@pubsubjs/react | react ^18.0.0 || ^19.0.0 |
TypeScript Configuration
Section titled “TypeScript Configuration”PubSubJS is written in TypeScript and ships with type definitions. For the best experience, ensure your tsconfig.json includes:
{ "compilerOptions": { "strict": true, "moduleResolution": "bundler", "esModuleInterop": true }}Verifying Installation
Section titled “Verifying Installation”Create a simple test file to verify your installation:
import { defineEvent } from "@pubsubjs/core";import { z } from "zod";
const events = defineEvent([ { name: "test.event", schema: z.object({ message: z.string() }), },]);
console.log("PubSubJS installed successfully!");console.log("Events:", Object.keys(events));Run it:
bun test.ts# ornpx ts-node test.tsNext Steps
Section titled “Next Steps”- Quick Start - Build your first application
- Events & Schemas - Learn about event definitions