An Astro adapter is an integration that turns the server part of your Astro build into something a specific runtime can execute: a Node.js server, a Cloudflare Worker, a Netlify Function or a Vercel Function. You only need an Astro adapter when some code must run per request, such as on-demand pages, server islands, actions, sessions or API endpoints that aren’t prerendered. A fully static site needs no adapter at all.
This guide explains what adapters do, how to tell whether your site needs one, how the official adapters compare, and the configuration details that trip people up in Astro 7.
Key Takeaways
- Static output (the default) builds plain files and runs on any host without an adapter.
- Any feature that runs at request time requires exactly one adapter for your deploy target.
npx astro add node(orcloudflare,netlify,vercel) installs and configures an adapter in one step.- With an adapter, pages are still prerendered by default; opt out per page with
export const prerender = false.- Adapters also decide runtime details: which Node.js APIs exist, how secrets are read and where sessions are stored.
What an Astro adapter actually does
When you run astro build without an adapter, Astro renders every page to HTML and writes static files to dist/. Nothing in the output runs code on a server.
With an adapter, the build has two parts. Prerendered pages still become static HTML. Everything that needs to run per request (on-demand pages, endpoints, server islands, actions, middleware for those routes) is bundled into a server entrypoint. The adapter’s job is to shape that entrypoint for one platform:
- Packaging. It writes the server code in the format the host expects: a standalone Node.js server, a Worker script, or function bundles in a host-specific folder.
- Routing. It tells the host which paths are static files and which go to the server code.
- Runtime glue. It converts the host’s request object into a standard
Request, passes it to Astro, and returns theResponse. It also exposes platform features like environment bindings, client IP addresses and caching. - Feature support. It declares which Astro features it supports, so Astro can warn or fail clearly when you use something the target can’t do.
You can see the difference in the build output: an adapter build has a server folder or function bundle next to the static assets, while a static build has only HTML, CSS, JavaScript and images.
Does your site need an Astro adapter?
Go through this list. If none apply, you don’t need an adapter.
| You use | Needs an adapter? |
|---|---|
| Static pages, content collections, MDX, images | No |
Client islands (client:load, client:visible) |
No |
getStaticPaths() and prerendered endpoints (.json.ts, rss.xml.js) |
No |
A page or endpoint with export const prerender = false |
Yes |
output: 'server' |
Yes |
Server islands (server:defer) |
Yes |
| Astro Actions | Yes |
Sessions (Astro.session) |
Yes |
| Reading cookies or headers per request | Yes |
| Middleware that must run on every request | Yes |
When an adapter is missing, Astro stops the build with a clear error. For on-demand pages it’s “Cannot use server-side rendering without an adapter”; for server islands it’s “Cannot use server islands without an adapter”; for actions it’s “Actions must be used with server output”. The fixes for no adapter installed and server islands without an adapter walk through each.
The official Astro adapters compared
Astro maintains four adapters. Community adapters exist for other targets such as Deno and various AWS setups, listed in the Astro integrations directory.
| Adapter | Package | Runs on | Best for |
|---|---|---|---|
| Node.js | @astrojs/node |
Any server with Node.js: VPS, container, PaaS | Full Node.js API, long-running servers, self-hosting |
| Cloudflare | @astrojs/cloudflare |
Cloudflare Workers (and Pages) | Global edge, bindings like KV, D1 and R2 |
| Netlify | @astrojs/netlify |
Netlify Functions and Edge Functions | Sites already on Netlify, Netlify image CDN |
| Vercel | @astrojs/vercel |
Vercel Functions | Sites already on Vercel, ISR-style caching |
The practical differences come down to runtime. The Node.js adapter gives you everything Node.js offers, including the file system and native modules. Cloudflare runs on the Workers runtime, which supports web-standard APIs and a large but incomplete set of Node.js APIs, so check libraries that depend on fs, net or native bindings. Netlify and Vercel run Node.js functions by default, with optional edge runtimes that have similar constraints to Workers.
Adding an adapter to an Astro project
The astro add command installs the package and edits astro.config.mjs for you:
npx astro add node
The result looks like this:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
site: 'https://www.example.com',
adapter: node({ mode: 'standalone' }),
});
Only one adapter can be active. If you deploy the same code to two hosts, choose the adapter with an environment variable in the config rather than listing both.
Adding an adapter doesn’t change any existing page. Astro 7’s default output: 'static' still prerenders everything; the adapter just makes on-demand rendering available. Opt individual routes in:
---
// src/pages/account.astro
export const prerender = false;
const user = Astro.cookies.get('session')?.value;
if (!user) return Astro.redirect('/login/');
---
<h1>Your account</h1>
If most of the site is dynamic, flip the default with output: 'server' and mark static pages with export const prerender = true. The rendering mode guide helps you choose, and the hybrid rendering tip shows mixed setups.
Configuring each Astro adapter
Node.js: standalone or middleware
The Node.js adapter has two modes:
mode: 'standalone'builds a server you start withnode ./dist/server/entry.mjs. It serves static files and on-demand routes. SetHOSTandPORTenvironment variables to control where it listens.mode: 'middleware'builds a handler you mount inside your own Express, Fastify or other Node.js server, useful when Astro is one part of a larger app.
// server.mjs (middleware mode with Express)
import express from 'express';
import { handler as astro } from './dist/server/entry.mjs';
const app = express();
app.use('/', express.static('dist/client/'));
app.use(astro);
app.listen(8080);
Cloudflare: bindings and the Workers runtime
The Cloudflare adapter exposes your Worker’s bindings (KV namespaces, D1 databases, R2 buckets, secrets) to Astro code. Configure them in your Wrangler config, and read them in server code through the adapter’s runtime API described in the Cloudflare adapter docs. Test with Wrangler locally to catch Node.js APIs the runtime doesn’t support. The Cloudflare Pages deploy docs cover the static side.
Netlify and Vercel: functions and caching
Both adapters turn on-demand routes into serverless functions automatically. They also integrate with each platform’s CDN caching, so a Cache-Control header with s-maxage on an on-demand page caches the response at the edge. Each adapter has options for edge middleware, image optimization through the platform’s image service, and platform-specific caching; check their docs for the current option names.
What changes at runtime with an adapter
Environment variables. Secrets declared in astro:env with access: 'secret' are read from the runtime through the adapter, so rotating a key in the host dashboard takes effect without a rebuild. The environment variables guide covers the details.
Sessions. Astro.session needs a storage driver. Several adapters configure a default for their platform; with others, set session.driver in astro.config.mjs.
Images. On-demand pages that use <Image /> optimize images at request time, so the adapter’s image service matters. Some adapters default to the host’s image CDN; others use Sharp, which needs a runtime that can run it.
Middleware. By default middleware runs at build time for prerendered pages and at request time for on-demand ones. Some adapters can deploy middleware as a separate edge function instead.
Cost and cold starts. Static files are served from a CDN and are effectively free. Server code costs compute time and may have cold starts on serverless platforms. Keeping most pages prerendered, and using server islands for the parts that must be dynamic, keeps both low. The server islands guide explains that pattern.
Choosing the right adapter
- Choose Node.js if you self-host, run in containers, need the full Node.js API, or want to avoid platform lock-in.
- Choose Cloudflare if you want low latency worldwide, already use Cloudflare, or need KV, D1 or R2 close to your code.
- Choose Netlify or Vercel if the site already deploys there and you want preview deployments, functions and caching managed for you.
- Choose no adapter if everything can be built ahead of time. Forms, search and comments can often use third-party services instead of server code.
Every Komal theme is built for static output and ships without an adapter, so it deploys to any host as-is. If you later add an account area or a form handled by Astro Actions, add the adapter for your host and set prerender = false only on those routes. Browse Astro themes or the Astro SSR guide for the server features in depth, and read Astro’s on-demand rendering docs for the official reference.
FAQ
What is an adapter in Astro?
An adapter is an integration that packages the server-rendered parts of an Astro build for a specific runtime, such as Node.js, Cloudflare Workers, Netlify Functions or Vercel Functions. It handles packaging, routing and the translation between the host’s requests and Astro’s standard Request and Response.
Do I need an adapter for a static Astro site?
No. A site built with the default output: 'static' and no on-demand routes produces plain files that any static host can serve. You only need an adapter for features that run per request.
Can I use more than one Astro adapter?
Not at the same time. A build uses one adapter. If you deploy to more than one host, choose the adapter in astro.config.mjs based on an environment variable so each deployment builds with the right one.
Which Astro adapter is fastest?
It depends on where your visitors and data are. Cloudflare runs close to visitors worldwide, while a Node.js server near your database can respond faster for data-heavy pages. Prerendering as many pages as possible matters more than the adapter choice.
Does adding an adapter make every page server-rendered?
No. With the default output: 'static', pages stay prerendered until you add export const prerender = false to a route. The adapter only makes on-demand rendering available.