Skip to Content

Frameworks

Full-stack

Vite + Nitro

Vite + Nitro on Vercel

Nitro is a universal server toolkit that adds server-side rendering (SSR), API routes, server middleware and other backend capabiltiies to any Vite application. It powers frameworks like Nuxt and deploys to Vercel with zero configuration.

By adding Nitro to your existing Vite project, you get:

  • Server-Side Rendering (SSR): Render pages dynamically on the server for improved SEO and faster initial page loads
  • API Routes: Create backend endpoints using file-based routing in the api/ or routes/ directory
  • Vercel Functions: Your server routes automatically become Vercel Functions with Fluid compute

Getting started

To add server capabilities to an existing Vite project, install the nitro package:

Adding API routes

yarn


npm

pnpm i nitro

bun

Then add the Nitro Vite plugin to your configuration:

});

plugins: [nitro()],

exportdefaultdefineConfig({

import { nitro } from'nitro/vite';

import { defineConfig } from'vite';

Dynamic routes

Create a file in the api/ directory to define a route:


This creates a GET /api/hello endpoint.

import { defineHandler } from'nitro/h3';

Nitro supports file-based routing in the api/ or routes/ directory. Each file becomes an API endpoint based on its path.

exportdefaultdefineHandler(() =>'Hello from the server!');

Use square brackets [param] for dynamic URL segments. Access params via event.context.params:

exportdefaultdefineHandler((event) => {

const { id } =event.context.params!;

This creates a GET /api/users/:id endpoint (e.g., /api/users/123).

});

return { userId: id };

Suffix your file with the HTTP method (.get.ts, .post.ts, .put.ts, .delete.ts):

import { defineHandler } from'nitro/h3';

import { defineHandler } from'nitro/h3';

exportdefaultdefineHandler(async (event) => {

constbody=awaitevent.req.json();

return { message:'User created', data: body };

});


Vercel Functions

When you deploy a Vite + Nitro app to Vercel, your server routes automatically become Vercel Functions with Fluid compute enabled by default.

Vercel Functions scale based on traffic demands, preventing failures during peak hours while minimizing costs during periods of low activity.

With Nitro on Vercel, you get:

  • Scaling to zero when not in use
  • Automatic scaling with traffic increases
  • Support for standard Web APIs, such as URLPattern, Response, and more

Learn more about Vercel Functions

Server-Side Rendering (SSR)

Nitro enables SSR for any Vite app with minimal configuration. The setup varies by UI framework.

Install the required dependencies:

pnpm

yarn


bun

pnpm i nitro react react-dom @vitejs/plugin-react

Create the shared app component:

Update your Vite config to add the Nitro and React plugins:

exportdefaultdefineConfig({

});

plugins: [nitro(),react()],

import { nitro } from'nitro/vite';

import { defineConfig } from'vite';

import react from'@vitejs/plugin-react';

Our Services

Digital Marketing

<>

import { useState } from'react';
return (
const [count,setCount] =useState(0);

);

Create the server entry file that renders your app to HTML:

import'@vitejs/plugin-react/preamble';

Vite + Nitro + React

exportfunctionApp() {
import { App } from'./app.tsx';

Create the client entry file that handles hydration:

setCount((c) => c +1)}>Count is {count}

}
import { hydrateRoot } from'react-dom/client';
hydrateRoot(document.querySelector('#app')!, );

import serverAssets from'./entry-server?assets=ssr';

import'./styles.css';

import { renderToReadableStream } from'react-dom/server.edge';

exportdefault {
returnnewResponse(

name="viewport"
/>
))}

{ headers: { 'Content-Type':'text/html;charset=utf-8' } },

,
))}

{

Update your TypeScript config:

"jsx":"react-jsx",

"compilerOptions": {

"extends":"nitro/tsconfig",

}

}

"jsxImportSource":"react"

To enable ISR for a Nitro route, add a routeRules option to your Nitro configuration:

Incremental Static Regeneration (ISR)

Incremental Static Regeneration (ISR) allows you to create or update content without redeploying your site. ISR has two main benefits for developers: better performance and faster build times.

import { defineNitroConfig } from'nitro/config';


routeRules: {

// All routes revalidate every 60 seconds in the background

'/**': { isr:60 },

'/static': { isr:true },

exportdefaultdefineNitroConfig({

// This route is generated on demand and cached permanently

},

});

// This route is always fresh

'/dynamic': { isr:false },

'/prerendered': { prerender:true },

// This route is prerendered at build time and cached permanently

Fine-grained ISR configuration

Pass an options object to the isr route rule to configure caching behavior:

  • expiration: Time in seconds before the cached page regenerates by invoking the function. Set to false (or use isr: true) to cache permanently.
  • allowQuery: List of query string parameter names cached independently. An empty array ignores query values. When undefined, each unique query value is cached independently.
  • passQuery: When true, the query string is passed to the invoked function. The allowQuery filter still applies.

isr: {

routeRules: {

'/products/**': {

allowQuery: ['q'],

import { defineNitroConfig } from'nitro/config';

},

},

},

expiration:60,

exportdefaultdefineNitroConfig({

passQuery:true,

On-demand revalidation

On-demand revalidation lets you purge the cache for an ISR route at any time, instead of waiting for the expiration interval.

To enable on-demand revalidation:

Create an environment variable to store a revalidation secret. Use the command openssl rand -base64 32 to generate a random value.

Add the bypassToken to your Nitro configuration:

vercel: {

config: {

bypassToken:process.env.VERCEL_BYPASS_TOKEN,

},

},

exportdefaultdefineNitroConfig({

});

Send a GET or HEAD request to the route with an x-prerender-revalidate header set to your bypassToken value. The cache revalidates immediately, and the next request returns a fresh response.

Using ISR with Vite + Nitro on Vercel offers:

  • Better performance with the global CDN
  • Zero-downtime rollouts to previously statically generated pages
  • Global content updates in 300ms
  • Generated pages are both cached and persisted to durable storage

Learn more about ISR

Environment variables

Vercel provides a set of System Environment Variables that are automatically available to your project.

To make environment variables accessible in Nitro server code, prefix the variable name with NITRO_ and define it in your Nitro configuration. For example, NITRO_API_TOKEN is accessible as useRuntimeConfig().apiToken.

runtimeConfig: {


},

});

exportdefaultdefineNitroConfig({

apiToken:'dev_token',// `dev_token` is the default value

import { defineNitroConfig } from'nitro/config';

In Nitro server code, access environment variables using useRuntimeConfig().

});

exportdefaultdefineHandler((event) => {

import { useRuntimeConfig } from'nitro/runtime-config';

import { defineHandler } from'nitro/h3';

returnuseRuntimeConfig().apiToken; // Returns `dev_token`

Observability

Learn more about Nitro runtime configuration


Learn more about Observability on Vercel

Vercel provides built-in observability for your Nitro applications, giving you visibility into your application's performance and behavior in production. Monitor function invocations, track errors, analyze latency, and inspect logs directly from the Vercel dashboard.

Learn more about deploying Vite + Nitro projects on Vercel:

See our Frameworks documentation page to learn about the benefits available to all frameworks when you deploy on Vercel.

Last updated August 11, 2026


TanStack Start

Was this helpful?

Cross-link map: Vite + Nitro on Vercel (/docs/frameworks/full-stack/vite-with-nitro)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesNitro on Vercel — Deploy Nitro applications to Vercel with zero configuration. Learn about observability, ISR, and custom build configuratHow to ship a Nitro app on Vercel — Deploy a Nitro app to Vercel with zero configuration. Learn how to ship from a template, the Vercel CLI, or Git, and conNuxt on Vercel — Deploy Nuxt applications to Vercel and configure rendering, functions, middleware, routing, image optimization, and cachWhat is the Nitro Vite plugin? — The Nitro Vite plugin \(nitro/vite\) adds SSR, API routes, and deploy-anywhere server builds to any Vite app. Learn whatSvelteKit on Vercel — Deploy SvelteKit applications to Vercel and configure the adapter, rendering, streaming, ISR, analytics, and Routing MidThis page links to (8)Vercel CDN overview — Vercel's CDN is a globally distributed platform that handles routing, caching, security, and compression for every deploSystem environment variables — System environment variables are automatically populated by Vercel, such as the URL of the deployment or the name of theFluid compute — Learn about fluid compute, an execution model for Vercel Functions that provides a more flexible and efficient way to ruFrameworks on Vercel — Vercel supports a wide range of the most popular frameworks, optimizing how your application builds and runs no matter wNuxt on Vercel — Deploy Nuxt applications to Vercel and configure rendering, functions, middleware, routing, image optimization, and cachVercel Functions — Build API routes, webhooks, and agent request handlers with Vercel Functions, then test and debug them with Vercel CLI.Incremental Static Regeneration \(ISR\) — ISR serves cached static pages while regenerating content in the background. Vercel\\Observability — Find production errors, capture request traces, and discover queryable metrics with Vercel Observability and Vercel CLI.Pages that link here (2)By site: vercel-kb (1) · vercel-docs (1)From vercel-kbWhat is the Nitro Vite plugin? — The Nitro Vite plugin \(nitro/vite\) adds SSR, API routes, and deploy-anywhere server builds to any Vite app. Learn whatFrom vercel-docsVite on Vercel — Deploy Vite projects to Vercel and configure environment variables, Vercel Functions, server-side rendering, and SPA rew