Sign In
Frontend & Clients

Node.js & Bun

The Rivet JavaScript client allows you to connect to and interact with actors from browser and Node.js applications.

Basic Usage

Installation

Install the RivetKit package:

npm install @rivetkit/actor

Create Client and Connect to Actor

Make sure you have a running Rivet actor server to connect to. You can follow the Node.js & Bun Quickstart to set up a simple actor server.

Create client and connect to actors and listen for real-time updates:

index.ts
import { createClient } from "@rivetkit/actor/client";
import type { Registry } from "../src/registry";

async function main() {
	const client = createClient<Registry>(
		process.env.ENDPOINT ?? "http://127.0.0.1:8080",
	);

	const counter = await client.counter.getOrCreate().connect();

	counter.on("countChanged", (count: number) => console.log("Count changed:", count));

	for (let i = 0; i < 5; i++) {
		const out = await counter.increment(1);
		console.log("Increment:", out);

		await new Promise((resolve) => setTimeout(resolve, 1000));
	}

	await new Promise((resolve) => setTimeout(resolve, 10000));
	await counter.dispose();
}

main();

API Reference

Follows the same API as the Node.js client, allowing you to use the same methods and properties for interacting with actors.

Suggest changes to this page