Skip to main content

Overview

This quickstart guide will help you build a complete TanStack Start application with:
  • File-based routing
  • Server-side rendering (SSR)
  • Server functions for data fetching
  • Type-safe RPC calls
  • Streaming with Suspense
By the end, you’ll have a working full-stack application that fetches data from a server function and renders it with SSR.

Step 1: Create Your Project

Start by creating a new directory and initializing a project:

Step 2: Install Dependencies

Install TanStack Start and its dependencies:

Step 3: Configure Vite

Create a vite.config.ts file:
vite.config.ts

Step 4: Configure TypeScript

Create a tsconfig.json file:
tsconfig.json

Step 5: Create a Server Function

Create a server function to fetch data. This code runs only on the server:
src/utils/posts.ts
Server functions are automatically transformed into API endpoints by the Vite plugin. The client-side calls become type-safe RPC requests.

Step 6: Create the Root Route

Create the root route with SSR setup:
src/routes/__root.tsx

Key Components for SSR

  • HeadContent: Renders meta tags, links, and scripts in the <head>
  • Scripts: Injects necessary client-side scripts for hydration
  • shellComponent: The outer HTML shell rendered on the server

Step 7: Create Route Pages

Create your route pages with data loading:
src/routes/index.tsx
src/routes/posts.index.tsx

Step 8: Create Router Configuration

Create the router configuration file:
src/router.tsx

Step 9: Generate Route Tree

Generate the route tree file. The TanStack Start plugin will auto-generate this file, but you need to create an initial version:
src/routeTree.gen.ts
In development, TanStack Router’s Vite plugin will automatically regenerate this file as you add or modify routes.

Step 10: Add Package Scripts

Update your package.json with the necessary scripts:
package.json

Step 11: Run Your Application

Start the development server:
Your application will be available at http://localhost:5173 (or another port if 5173 is in use).

What’s Happening?

  1. SSR: Pages are rendered on the server first
  2. Server Functions: The fetchPosts function runs on the server
  3. Hydration: The client-side JavaScript makes the page interactive
  4. Type Safety: Full type safety from server to client

Step 12: Test Server Functions

Visit http://localhost:5173/posts and check your server logs. You should see:
This confirms that the server function is running on the server, not the client.

Advanced: Streaming with Suspense

Add streaming support for better perceived performance:
src/routes/posts.deferred.tsx
The page will render immediately with the fallback, then stream in the deferred data when ready.

Build for Production

Build your application for production:
This creates optimized builds in the .output directory:
  • .output/public/: Static client assets
  • .output/server/: Server bundle
Run the production server:

Next Steps

Congratulations! You’ve built your first TanStack Start application. Here’s what to explore next:

Server Functions

Deep dive into server functions, validation, and error handling

SSR & Streaming

Learn about advanced SSR and streaming patterns

API Routes

Create custom API endpoints for external clients

Deployment

Deploy your app to Netlify, Vercel, Cloudflare, and more