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

Quickstart

1

Create a new Node.js project

Create a new Node.js project with TypeScript support:

mkdir my-app
cd my-app
npm init -y
npm pkg set type=module
2

Install RivetKit packages

Install the RivetKit client and Node.js platform packages:

npm install @rivetkit/actor
3

Create your client

Create a file src/client.ts in your project to connect to your actor:

src/client.ts
import { createClient } from "@rivetkit/actor/client";
import type { App } from "../actors/app";

async function main() {
  // Replace with your endpoint URL after deployment
  const client = createClient<App>("http://localhost:8080");

  // Get or create a actor instance
  const counter = await client.counter.get();

  // Subscribe to events
  counter.on("newCount", (count: number) => console.log("Event:", count));

  // Call an action
  const out = await counter.increment(5);
  console.log("Action:", out);

  // Clean up when done
  await counter.dispose();
}

main().catch(console.error);
4

Run your client

In a separate terminal, run your client code:

npx tsx src/client.ts

You should see output like:

Event: 5
Action: 5

Run it again to see the state update.

Next Steps

For more information on communicating with actors, including event handling and RPC calls, see Communicating with Actors.