The RivetKit JavaScript client allows you to connect to and interact with actors from browser and Node.js applications.
Quickstart
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
Install RivetKit packages
Install the RivetKit client and Node.js platform packages:
npm install @rivetkit/actor
Create your client
Create a file src/client.ts
in your project to connect to your actor:
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);
Run your client
In a separate terminal, run your client code:
You should see output like:
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.
Responses are generated using AI and may contain mistakes.