| title | Node.js & Bun |
|---|---|
| icon | node-js |
import MvpWarning from "/snippets/mvp-warning.mdx"; import StepDefineActor from "/snippets/step-define-actor.mdx"; import StepRunStudio from "/snippets/step-run-studio.mdx"; import StepDeploy from "/snippets/step-deploy.mdx"; import SetupNextSteps from "/snippets/setup-next-steps.mdx";
The RivetKit JavaScript client allows you to connect to and interact with actors from browser and Node.js applications.
Create a new Node.js project with TypeScript support:<CodeGroup>
```sh npm
mkdir my-app
cd my-app
npm init -y
npm pkg set type=module
```
```sh pnpm
mkdir my-app
cd my-app
pnpm init
pnpm pkg set type=module
```
```sh yarn
mkdir my-app
cd my-app
yarn init -y
yarn pkg set type=module
```
```sh bun
mkdir my-app
cd my-app
bun init -y
```
</CodeGroup>
<CodeGroup>
```sh npm
npm install rivetkit
```
```sh pnpm
pnpm add rivetkit
```
```sh yarn
yarn add rivetkit
```
```sh bun
bun add rivetkit
```
</CodeGroup>
```typescript src/client.ts
import { createClient } from "rivetkit/client";
import type { App } from "../actors/app";
async function main() {
// Replace with your endpoint URL after deployment
const client = createClient<App>("http://localhost:6420");
// 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);
```
<CodeGroup>
```sh npm
npx tsx src/client.ts
```
```sh pnpm
pnpm exec tsx src/client.ts
```
```sh yarn
yarn tsx src/client.ts
```
```sh bun
bun run src/client.ts
```
</CodeGroup>
You should see output like:
```
Event: 5
Action: 5
```
Run it again to see the state update.
See the Interacting with Actors documentation for information on how to use the client.