Vue Quickstart
Get a SpacetimeDB Vue app running in under 5 minutes.
Prerequisites
- Node.js 18+ installed
- SpacetimeDB CLI installed
Run the spacetime dev command to create a new project with a SpacetimeDB module and Vue client.
This will start the local SpacetimeDB server, publish your module, generate TypeScript bindings, and start the Vue development server.
spacetime dev --template vue-tsNavigate to http://localhost:5173 to see your app running.
The template includes a basic Vue app connected to SpacetimeDB.
Your project contains both server and client code.
Edit spacetimedb/src/index.ts to add tables and reducers. Edit src/App.vue to build your UI.
my-spacetime-app/
├── spacetimedb/ # Your SpacetimeDB module
│ └── src/
│ └── index.ts # Server-side logic
├── src/ # Vue frontend
│ ├── App.vue
│ └── module_bindings/ # Auto-generated types
└── package.json
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.
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!');
});Use the SpacetimeDB CLI to call reducers and query your data directly.
# 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!Next steps
- Read the TypeScript SDK Reference for detailed API docs