<html lang="en">
<head></head>
<body>

<form id="mainForm" method="post" action="https://stackblitz.com/run" target="_self">
<input type="hidden" name="project[files][.gitignore]" value=".actorcore
node_modules">
<input type="hidden" name="project[files][README.md]" value="# Deno Example for RivetKit

Example project demonstrating basic actor state management and RPC calls with [RivetKit](https://rivetkit.org) using Deno runtime.

[Learn More →](https://github.com/rivet-dev/rivetkit)

[Discord](https://rivet.dev/discord) — [Documentation](https://rivetkit.org) — [Issues](https://github.com/rivet-dev/rivetkit/issues)

## Getting Started

### Prerequisites

- Deno

### Installation

```sh
git clone https://github.com/rivet-dev/rivetkit
cd rivetkit/examples/deno
pnpm install
```

**Notice:** We use `pnpm install` here as Deno offers compatability with package.json via npm/pnpm. Some packages used in rivetkit are simpler to install with npm/pnpm.

### Development

```sh
deno task dev
```

Run the connect script to interact with the counter:

```sh
deno task connect
```

## License

Apache 2.0">
<input type="hidden" name="project[files][deno.json]" value="{
  &quot;tasks&quot;: {
    &quot;dev&quot;: &quot;deno run --allow-env --allow-sys --allow-read --allow-ffi --allow-net src/server.ts&quot;,
    &quot;check-types&quot;: &quot;deno check src/**/*.ts&quot;,
    &quot;test&quot;: &quot;deno test --allow-env --allow-sys --allow-read --allow-ffi --allow-net&quot;,
    &quot;connect&quot;: &quot;deno run --allow-env --allow-sys --allow-read --allow-ffi --allow-net scripts/connect.ts&quot;
  },
  &quot;imports&quot;: {
    &quot;os&quot;: &quot;node:os&quot;,
    &quot;path&quot;: &quot;node:path&quot;,
    &quot;fs&quot;: &quot;node:fs&quot;,
    &quot;fs/promises&quot;: &quot;node:fs/promises&quot;,
    &quot;crypto&quot;: &quot;node:crypto&quot;,
    &quot;rivetkit&quot;: &quot;../../packages/rivetkit/dist/tsup/mod.js&quot;,
    &quot;rivetkit/client&quot;: &quot;../../packages/rivetkit/dist/tsup/client/mod.js&quot;,
    &quot;hono&quot;: &quot;npm:hono@4.9.8&quot;,
    &quot;hono/ws&quot;: &quot;npm:hono@4.9.8/ws&quot;,
    &quot;hono/deno&quot;: &quot;npm:hono@4.9.8/deno&quot;
  },
  &quot;compilerOptions&quot;: {
    &quot;skipLibCheck&quot;: true,
    &quot;strict&quot;: false,
    &quot;noImplicitAny&quot;: false
  }
}
">
<input type="hidden" name="project[files][package.json]" value="{&quot;//&quot;:&quot;This package.json is required, once is released with updated engine-runner packages, it can be converted to deno.json&quot;,&quot;name&quot;:&quot;example-deno&quot;,&quot;version&quot;:&quot;2.0.20&quot;,&quot;private&quot;:true,&quot;type&quot;:&quot;module&quot;,&quot;scripts&quot;:{&quot;dev&quot;:&quot;deno run --allow-all src/server.ts&quot;,&quot;check-types&quot;:&quot;deno task check-types&quot;,&quot;connect&quot;:&quot;deno run --allow-all scripts/connect.ts&quot;},&quot;devDependencies&quot;:{&quot;@types/deno&quot;:&quot;^2.3.0&quot;,&quot;@types/node&quot;:&quot;^24.5.2&quot;},&quot;stableVersion&quot;:&quot;0.8.0&quot;,&quot;dependencies&quot;:{&quot;hono&quot;:&quot;4.9.8&quot;,&quot;rivetkit&quot;:&quot;https://pkg.pr.new/rivet-dev/rivetkit/rivetkit@54999214372f9ecb3f4251a3be45c7a0eb8dfacf&quot;}}">
<input type="hidden" name="project[files][tsconfig.json]" value="{
  &quot;compilerOptions&quot;: {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    &quot;target&quot;: &quot;esnext&quot;,
    /* Specify a set of bundled library declaration files that describe the target runtime environment. */
    &quot;lib&quot;: [&quot;esnext&quot;, &quot;DOM&quot;],
    /* Specify what JSX code is generated. */
    &quot;jsx&quot;: &quot;react-jsx&quot;,

    /* Specify what module code is generated. */
    &quot;module&quot;: &quot;esnext&quot;,
    /* Specify how TypeScript looks up a file from a given module specifier. */
    &quot;moduleResolution&quot;: &quot;bundler&quot;,
    /* Specify type package names to be included without being referenced in a source file. */
    &quot;types&quot;: [&quot;deno&quot;],
    /* Enable importing .json files */
    &quot;resolveJsonModule&quot;: true,

    /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
    &quot;allowJs&quot;: true,
    /* Enable error reporting in type-checked JavaScript files. */
    &quot;checkJs&quot;: false,

    /* Disable emitting files from a compilation. */
    &quot;noEmit&quot;: true,

    /* Ensure that each file can be safely transpiled without relying on other imports. */
    &quot;isolatedModules&quot;: true,
    /* Allow &#39;import x from y&#39; when a module doesn&#39;t have a default export. */
    &quot;allowSyntheticDefaultImports&quot;: true,
    /* Ensure that casing is correct in imports. */
    &quot;forceConsistentCasingInFileNames&quot;: true,
    /* Allow imports to include TypeScript file extensions. */
    &quot;allowImportingTsExtensions&quot;: true,

    /* Enable all strict type-checking options. */
    &quot;strict&quot;: true,

    /* Skip type checking all .d.ts files. */
    &quot;skipLibCheck&quot;: true
  },
  &quot;include&quot;: [&quot;src/**/*.ts&quot;, &quot;scripts/**/*.ts&quot;, &quot;tests/**/*.ts&quot;]
}
">
<input type="hidden" name="project[files][scripts/connect.ts]" value="import { createClient } from &quot;rivetkit/client&quot;;
import type { Registry } from &quot;../src/registry.ts&quot;;

async function main() {
	const client = createClient&lt;Registry&gt;(&quot;http://localhost:8080&quot;);

	const counter = client.counter.getOrCreate().connect();

	for (let i = 0; i &lt; 5; i++) {
		const out = await counter.increment(5);
		console.log(&quot;RPC:&quot;, out);

		await new Promise((resolve) =&gt; setTimeout(resolve, 1000));
	}
}

main();
">
<input type="hidden" name="project[files][src/registry.ts]" value="import { actor, setup } from &quot;rivetkit&quot;;

const counter = actor({
	state: {
		count: 0,
	},
	actions: {
		increment: (c, x: number) =&gt; {
			c.state.count += x;
			c.broadcast(&quot;newCount&quot;, c.state.count);
			return c.state.count;
		},
		getCount: (c) =&gt; {
			return c.state.count;
		},
	},
});

export const registry = setup({
	use: { counter },
});

export type Registry = typeof registry;
">
<input type="hidden" name="project[files][src/server.ts]" value="import { upgradeWebSocket } from &quot;hono/deno&quot;;
import { registry } from &quot;./registry.ts&quot;;

const { fetch } = registry.start({
	// Deno requires using Deno.serve
	disableDefaultServer: true,
	overrideServerAddress: &quot;http://localhost:8080&quot;,
	// Specify Deno-specific upgradeWebSocket
	getUpgradeWebSocket: () =&gt; upgradeWebSocket,
});

// Start server
Deno.serve({ port: 8080 }, fetch);
">
<input type="hidden" name="project[description]" value="generated by https://pkg.pr.new">
<input type="hidden" name="project[template]" value="node">
<input type="hidden" name="project[title]" value="example-deno">
</form>
<script>document.getElementById("mainForm").submit();</script>

</body></html>