Fastify is a fast, low-overhead web framework for building backend servers in Node.js. It pairs a plugin-based architecture with schema-based validation, lifecycle hooks, and built-in logging, and it ships first-class TypeScript support.
On Vercel, you can deploy a Fastify app with zero configuration. Your app runs as a Vercel Function on Fluid compute, with preview deployments, instant rollback, and the Vercel Firewall available without extra setup.
This guide walks you through deploying a Fastify app to Vercel from a template, the Vercel CLI, or a Git repository, then configuring features such as streaming, lifecycle hooks, cron jobs, and observability.
Before you begin, make sure you have:
- A Vercel account
- Node.js 20+ and a package manager (e.g., npm)
- An existing Fastify project, or a new one created from the Fastify on Vercel template
- A Git repository on GitHub, GitLab, or Bitbucket (if you want Git-based deployments)
- Vercel CLI installed (
npm i -g vercel)
When you deploy a Fastify app, Vercel detects the framework and builds it for the Vercel runtime. Your app is deployed as a single Vercel Function that runs on Fluid compute by default, so it scales with traffic, and you pay only for the compute your function uses, not for idle time.
Because Vercel ships zero-configuration detection for Fastify, you don't set a build command or output directory. Vercel reads your project, finds your entry point file, and applies the correct build settings.
You can ship a Fastify app to Vercel in three ways. Choose the one that fits where your code lives today.
The fastest way to ship a Fastify app is to start from the Fastify on Vercel template, a minimal Fastify API that deploys with zero configuration. When you deploy it, Vercel clones the template to your Git provider, creates a project, and deploys it.
To scaffold a new Fastify project locally, use the Vercel CLI init command. It clones Vercel's Fastify example into a folder named fastify.
- Create the project:
- Install dependencies:
- Develop locally at
http://localhost:3000withvercel dev, so your app runs the same way it does in production: - Create a preview deployment. The first run links a Vercel project:
- Promote your deployment to production:
If you already have a Fastify app, deploy it from Git or from the command line.
From Git: Push your project to GitHub, GitLab, or Bitbucket, then import it at vercel.com/new. Vercel detects Fastify automatically and deploys it with zero configuration.
From the CLI: From your project's root directory, run vercel to create a preview deployment, then vercel --prod to go live. To pull project settings and environment variables for local development, run:
For Vercel to detect your app, name your entry point one of the recognized files, such as app.ts, index.ts, or server.ts at your project root or under src/. Create your Fastify instance, register your routes, and start the server with fastify.listen():
After your app is deployed, you can layer Vercel features onto it. Some work automatically, and others take a few lines of configuration in vercel.json.
Your entire Fastify app is served by a single Vercel Function, which uses Fluid compute by default. Fluid compute runs multiple requests concurrently within a single instance to reduce cold starts and the cost of I/O-bound work such as API calls and database queries. You don't configure anything to get this behavior.
Because your app is deployed as one function, Vercel routes every incoming request to it and lets Fastify's router match the path. Your route handlers, lifecycle hooks, and error handling all run inside the function.
Vercel Functions support streaming, so you can send data to the client as you produce it instead of waiting for the full response. Fastify streams a response when you return a Node.js Readable stream from a handler. It pipes the stream to the client and ends the response when the stream finishes.
Streaming pairs well with Fluid compute: while your function waits between chunks, the same instance can serve other requests. To stream model output, send a stream from AI SDK directly. Return result.textStream for plain text, or result.toUIMessageStream() to stream structured UI messages from streamText:
Fastify and Vercel each have a layer for running code around requests, and they solve different problems. Fastify's lifecycle hooks run inside your app, after the request reaches your function. Use them for app-level concerns such as logging, authentication, and request processing, and register them with fastify.addHook:
Vercel Routing Middleware runs at the edge, before the request reaches your Fastify app. Use it for rewrites, redirects, and header changes that should happen before any function runs. The two layers work together, with Routing Middleware shaping the request at the edge and Fastify's hooks handling it inside your app.
Vercel Cron Jobs trigger a route on a schedule by sending an HTTP GET request to it. Define a route in your Fastify app for the task, then register the schedule in vercel.json.
Define the route:
Register the schedule:
Vercel runs cron jobs only on production deployments. To stop anyone else from calling the route, set a CRON_SECRET environment variable in your project settings. Vercel sends it as a Bearer token in the Authorization header on every cron invocation, and your handler compares it before running the task.
Vercel Observability tracks your deployed functions automatically, with no setup. Open the Observability page in your project to see invocation counts, error rates, and duration for your Fastify app, along with the requests your functions make to external APIs. On Observability Plus, you also get longer retention and a latency breakdown by path.
Vercel finds your Fastify app by looking for an entry point at a fixed set of locations: app, index, or server (with a .js, .ts, .mjs, .cjs, .mts, or .cts extension) at your project root or under src/. Put your app at one of these paths so Vercel detects and deploys it correctly:
Create your Fastify instance, register your routes, and call fastify.listen() in this file. Vercel uses it as the function entry point for every request.
Run vercel dev for local development instead of starting the server another way. It serves your app the same way production does, so the behavior you test locally matches what you deploy. This also lets you exercise features such as cron routes before shipping. Vercel CLI 48.6.0 or later is required.
- Read the full Fastify on Vercel documentation
- Deploy the Fastify on Vercel template in one step
- Learn how Vercel Functions run your server code
- Understand pricing and scaling with Fluid compute
- Run code before requests with Routing Middleware
- Recover from bad deploys with Instant Rollback
- Explore the Fastify documentation for framework details