Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions docs/docs/00100-intro/00200-quickstarts/00155-nuxt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
title: Nuxt Quickstart
sidebar_label: Nuxt
slug: /quickstarts/nuxt
hide_table_of_contents: true
---

import { InstallCardLink } from "@site/src/components/InstallCardLink";
import { StepByStep, Step, StepText, StepCode } from "@site/src/components/Steps";


Get a SpacetimeDB Nuxt app running in under 5 minutes.

## Prerequisites

- [Node.js](https://nodejs.org/) 18+ installed
- [SpacetimeDB CLI](https://spacetimedb.com/install) installed

<InstallCardLink />

---

<StepByStep>
<Step title="Create your project">
<StepText>
Run the `spacetime dev` command to create a new project with a SpacetimeDB module and Nuxt client.

This will start the local SpacetimeDB server, publish your module, generate TypeScript bindings, and start the Nuxt development server.
</StepText>
<StepCode>
```bash
spacetime dev --template nuxt-ts
```
</StepCode>
</Step>

<Step title="Open your app">
<StepText>
Navigate to [http://localhost:5173](http://localhost:5173) to see your app running.

The template includes a basic Nuxt app connected to SpacetimeDB.
</StepText>
</Step>

<Step title="Explore the project structure">
<StepText>
Your project contains both server and client code.

Edit `spacetimedb/src/index.ts` to add tables and reducers. Edit `components/AppContent.vue` to build your UI, and `app.vue` to configure the SpacetimeDB connection.
</StepText>
<StepCode>
```
my-spacetime-app/
├── spacetimedb/ # Your SpacetimeDB module
│ └── src/
│ └── index.ts # Server-side logic
├── app.vue # Root component
├── components/
│ └── AppContent.vue # Main UI component
├── module_bindings/ # Auto-generated types
├── nuxt.config.ts # Nuxt configuration
└── package.json
```
</StepCode>
</Step>

<Step title="Understand tables and reducers">
<StepText>
Open `spacetimedb/src/index.ts` to see the module code. The template includes a `person` table and two reducers: `add` to insert a person, and `say_hello` to greet everyone.

Tables store your data. Reducers are functions that modify data — they're the only way to write to the database.
</StepText>
<StepCode>
```typescript
import { schema, table, t } from 'spacetimedb/server';

export const spacetimedb = schema(
table(
{ name: 'person', public: true },
{
name: t.string(),
}
)
);

spacetimedb.reducer('add', { name: t.string() }, (ctx, { name }) => {
ctx.db.person.insert({ name });
});

spacetimedb.reducer('say_hello', (ctx) => {
for (const person of ctx.db.person.iter()) {
console.info(`Hello, ${person.name}!`);
}
console.info('Hello, World!');
});
```
</StepCode>
</Step>

<Step title="Test with the CLI">
<StepText>
Use the SpacetimeDB CLI to call reducers and query your data directly.
</StepText>
<StepCode>
```bash
# Call the add reducer to insert a person
spacetime call <database-name> add Alice

# Query the person table
spacetime sql <database-name> "SELECT * FROM person"
name
---------
"Alice"

# Call say_hello to greet everyone
spacetime call <database-name> say_hello

# View the module logs
spacetime logs <database-name>
2025-01-13T12:00:00.000000Z INFO: Hello, Alice!
2025-01-13T12:00:00.000000Z INFO: Hello, World!
```
</StepCode>
</Step>
</StepByStep>

## Next steps

- Read the [TypeScript SDK Reference](/sdks/typescript) for detailed API docs
Loading
Loading