1
+ import { Hosting } from " @/components/docs/Hosting" ;
2
+
1
3
# Node.js & Bun Quickstart
2
4
3
5
Get started with Rivet Actors in Node.js and Bun
@@ -15,7 +17,7 @@ npm install @rivetkit/actor
15
17
16
18
Create a simple counter actor:
17
19
18
- ``` ts registry.ts
20
+ ``` ts {{"title":" registry.ts"}}
19
21
import { actor , setup } from " @rivetkit/actor" ;
20
22
21
23
export const counter = actor ({
@@ -43,7 +45,7 @@ Choose your preferred web framework:
43
45
44
46
<CodeGroup >
45
47
46
- ``` ts Hono
48
+ ``` ts {{"title":" Hono"}}
47
49
import { registry } from " ./registry" ;
48
50
import { Hono } from " hono" ;
49
51
@@ -68,7 +70,7 @@ app.post("/increment/:name", async (c) => {
68
70
serve (app );
69
71
```
70
72
71
- ``` ts Express.js
73
+ ``` ts {{"title":" Express.js"}}
72
74
import { registry } from " ./registry" ;
73
75
import express from " express" ;
74
76
@@ -97,7 +99,7 @@ app.listen(8080, () => {
97
99
});
98
100
```
99
101
100
- ``` ts Elysia
102
+ ``` ts {{"title":" Elysia"}}
101
103
import { registry } from " ./registry" ;
102
104
import { Elysia } from " elysia" ;
103
105
@@ -132,11 +134,11 @@ The `/registry` endpoint is automatically mounted by Rivet and is required for c
132
134
133
135
<CodeGroup >
134
136
135
- ``` sh Node.js
137
+ ``` sh {{"title":" Node.js"}}
136
138
npx tsx --watch server.ts
137
139
```
138
140
139
- ``` sh Bun
141
+ ``` sh {{"title":" Bun"}}
140
142
bun --watch server.ts
141
143
```
142
144
@@ -152,7 +154,7 @@ Test your counter actor using HTTP requests:
152
154
153
155
<CodeGroup >
154
156
155
- ``` ts JavaScript
157
+ ``` ts {{"title":" JavaScript"}}
156
158
// Increment counter
157
159
const response = await fetch (" http://localhost:8080/increment/my-counter" , {
158
160
method: " POST"
@@ -173,115 +175,7 @@ curl -X POST http://localhost:8080/increment/my-counter
173
175
174
176
<Step title = " Deploy" >
175
177
176
- By default, Rivet stores actor state on the local file system and will not scale in production.
177
-
178
- The following providers let you deploy & scale Rivet:
179
-
180
- <Tabs >
181
-
182
- <Tab title = " Redis" >
183
-
184
- For production with Redis storage, install the Redis driver:
185
-
186
- ``` sh
187
- npm install @rivetkit/redis
188
- ```
189
-
190
- Then configure the driver:
191
-
192
- ``` ts server.ts
193
- import { registry } from " ./registry" ;
194
-
195
- const { client, serve } = registry .createServer ({
196
- driver: createRedisDriver ()
197
- });
198
-
199
- // ... rest of server setup ...
200
- ```
201
-
202
- Your backend can now be deployed to your cloud provider of choice.
203
-
204
- </Tab >
205
-
206
- <Tab title = " Cloudflare Workers" >
207
-
208
- Deploy to Cloudflare Workers, install the Cloudflare Workers driver:
209
-
210
- ``` sh
211
- npm install @rivetkit/cloudflare-workers
212
- ```
213
-
214
- Update your ` server.ts ` to support Cloudflare Workers:
215
-
216
- <CodeGroup >
217
-
218
- ``` ts Hono
219
- import { createServer } from " @rivetkit/cloudflare-workers" ;
220
- import { Hono } from " hono" ;
221
- import { registry } from " ./registry" ;
222
-
223
- const { client, createHandler } = createServer (registry );
224
-
225
- // Setup router
226
- const app = new Hono ();
227
-
228
- // ... etc ...
229
-
230
- const { handler, ActorHandler } = createHandler (app );
231
-
232
- export { handler as default , ActorHandler };
233
- ```
234
-
235
- ``` ts No Router
236
- import { createServerHandler } from " @rivetkit/cloudflare-workers" ;
237
- import { registry } from " ./registry" ;
238
-
239
- const { handler, ActorHandler } = createServerHandler (registry );
240
- export { handler as default , ActorHandler };
241
- ```
242
-
243
- </CodeGroup >
244
-
245
- Update your configuration file to support ` ACTOR_DO ` and ` ACTOR_KV ` bindings:
246
-
247
- ``` json wrangler.json
248
- {
249
- "name" : " my-rivetkit-app" ,
250
- "main" : " src/index.ts" ,
251
- "compatibility_date" : " 2025-01-20" ,
252
- "compatibility_flags" : [" nodejs_compat" ],
253
- "migrations" : [
254
- {
255
- "tag" : " v1" ,
256
- "new_classes" : [" ActorHandler" ]
257
- }
258
- ],
259
- "durable_objects" : {
260
- "bindings" : [
261
- {
262
- "name" : " ACTOR_DO" ,
263
- "class_name" : " ActorHandler"
264
- }
265
- ]
266
- },
267
- "kv_namespaces" : [
268
- {
269
- "binding" : " ACTOR_KV" ,
270
- "id" : " your_namespace_id"
271
- }
272
- ]
273
- }
274
- ```
275
-
276
- Finally, deploy:
277
-
278
- ``` sh
279
- wrangler deploy
280
- ```
281
-
282
- </Tab >
283
-
284
- </Tabs >
178
+ <Hosting />
285
179
286
180
</Step >
287
181
@@ -297,7 +191,7 @@ Create a type-safe client to connect from your frontend:
297
191
298
192
<Tab title = " JavaScript" >
299
193
300
- ``` ts
194
+ ``` ts {{"title":"client.ts"}}
301
195
import { createClient } from " @rivetkit/actor/client" ;
302
196
import type { registry } from " ./registry" ;
303
197
@@ -331,7 +225,7 @@ See the [JavaScript client documentation](/clients/javascript) for more informat
331
225
332
226
<Tab title = " React" >
333
227
334
- ``` tsx
228
+ ``` tsx {{"title":"Counter.tsx"}}
335
229
import { useState } from " react" ;
336
230
import { createClient , createRivetKit } from " @rivetkit/react" ;
337
231
import type { registry } from " ./registry" ;
@@ -370,7 +264,7 @@ See the [React documentation](/clients/react) for more information.
370
264
371
265
<Tab title = " Rust" >
372
266
373
- ``` rust
267
+ ``` rust {{"title":"main.rs"}}
374
268
use rivetkit_client :: {Client , EncodingKind , GetOrCreateOptions , TransportKind };
375
269
use serde_json :: json;
376
270
0 commit comments