Skip to content

Installation

PubSubJS is distributed as multiple packages. Install only what you need.

The core package is required for all PubSubJS applications:

Terminal window
# Using bun (recommended)
bun add @pubsubjs/core
# Using npm
npm install @pubsubjs/core
# Using yarn
yarn add @pubsubjs/core
# Using pnpm
pnpm add @pubsubjs/core

PubSubJS supports any Standard Schema compatible validation library. Install your preferred library:

Terminal window
# Zod (recommended)
bun add zod
# Valibot (smaller bundle size)
bun add valibot
# ArkType
bun add arktype

Install the transport(s) you need:

For real-time browser-server communication:

Terminal window
bun add @pubsubjs/transport-websocket

For distributed systems and microservices:

Terminal window
bun add @pubsubjs/transport-redis

For server-to-client streaming:

Terminal window
bun add @pubsubjs/transport-sse

For React applications:

Terminal window
bun add @pubsubjs/react

Some packages have peer dependencies:

PackagePeer Dependencies
@pubsubjs/corezod or valibot (optional)
@pubsubjs/reactreact ^18.0.0 || ^19.0.0

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
}
}

Create a simple test file to verify your installation:

test.ts
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:

Terminal window
bun test.ts
# or
npx ts-node test.ts