Nuxt 14 ๐ Deployment & Nitro Presets โ Building .output/ and deploying to Node.js, static hosts, Vercel, Netlify, and Cloudflare
Every Nuxt application is actually two applications stapled together. There is a Vue front end that ships to the browser, and there is a Nitro server that runs your API routes, renders HTML on the server, and handles middleware. The front end is portable โ it is JavaScript and HTML and it runs anywhere. The server is not. A Node.js process, a Lambda function, an edge worker, and a static file host have completely different execution models, different filesystems, and different cold-start characteristics.
Nitro exists to absorb that difference. It is the server engine that Nuxt builds on top of, and its central idea is the preset: a named adapter that tells the build which runtime the output must target. When you run nuxt build, Nitro reads the preset, compiles the server into a shape that runtime can execute, and writes everything into a single .output/ directory. Change the preset and the same application produces a structurally different artifact without a single line of source changing.
This chapter covers three things. First, the anatomy of .output/ โ what is inside public/, server/, and why the split matters for caching and CDN configuration. Second, the preset system itself: node-server, static, vercel, netlify, and the Cloudflare variants, including the runtime each one targets and the constraints it imposes. Third, the deployment mechanics that every target shares โ runtimeConfig and NUXT_ environment variables, and how a value supplied at build time differs from one supplied at startup.
Key point: Nitro compiles a Nuxt server into .output/ for a specific runtime chosen by the preset, so the same application deploys to a Node process, a serverless function, or an edge worker by changing the preset rather than the code โ and environment variables must flow through runtimeConfig because a serverless bundle is built before it is deployed.
Why Nitro Presets exist
The universal server problem. A Nuxt server does real work: it renders pages to HTML, runs server/api handlers, executes route middleware, and manages sessions. That work has to happen somewhere at request time. The place it happens โ a long-lived process, a short-lived function, or an edge worker โ dictates how the code is compiled, what APIs are available, and how large the bundle may be. A single “just run it” build would only ever work on one of those.
The filesystem problem. A Node server can read files from disk and write to disk at runtime. A serverless function gets a read-only filesystem outside /tmp, and an edge worker gets no filesystem at all. Nitro inlines the server logic into the bundle so the artifact does not depend on files existing beside it. That is why .output/server/ is a self-contained JavaScript entry point rather than a folder of scripts that read from disk.
The cold-start problem. A serverless function must boot in milliseconds. The heavier the bundle and the more modules it imports at the top level, the longer the first request waits. Nitro produces a tree-shaken, pre-bundled server precisely to keep that boot cost low, and the edge presets go further by requiring that the bundle contain no Node built-ins at all.
The static hosting problem. Not every application needs a server running continuously. A marketing site or documentation portal can be rendered once and served as files. The static preset exists to pre-render every route at build time and emit a directory that any static host โ or a plain S3 bucket โ can serve with no compute behind it.
The configuration drift problem. The same application behaves differently in development and production, and the difference is usually configuration. runtimeConfig exists so values can be injected at startup instead of baked at build, which is what lets a container image built once be promoted across staging and production without being rebuilt for each.
The vendor lock-in problem. Every platform wants its own SDK calls, its own handler signature, and its own way of exposing the request. Nitro’s preset layer means the platform-specific glue is generated, not written, so moving from Vercel to Cloudflare is a preset change and a redeploy rather than a rewrite.
a. The .output/ directory and the build pipeline
Running nuxt build executes three sequential phases: the client build compiles the Vue application with Vite, the server build compiles the Nitro handlers and the SSR renderer, and the prerender phase renders any routes marked for static generation. The result is one directory with a fixed shape.
# The .output/ directory after `nuxt build`
.output/
โโโ public/ # static client assets, served as-is by a CDN
โ โโโ _nuxt/ # hashed JS and CSS chunks (immutably cacheable)
โ โโโ ... # files copied from the public/ directory
โโโ server/ # the Nitro server bundle, self-contained
โ โโโ index.mjs # entry point the preset expects to invoke
โ โโโ chunks/ # compiled server code split into chunks
โ โโโ package.json # runtime dependency manifest
โโโ nitro.json # build metadata: preset name, output paths
The split between public/ and server/ is the single most important thing to understand about deployment. Everything in public/ is static, identical for every user, and safe to serve from a CDN with long cache lifetimes. Everything in server/ is executed per request. A platform configuration that sends all requests to the server wastes the CDN; one that sends all requests to the CDN breaks every API route.
The _.<hash>.js filenames inside public/_nuxt/ are content-hashed, which means the bytes named by the hash can never change. That makes them cacheable forever with Cache-Control: public, max-age=31536000, immutable. The HTML pages the server returns are the opposite: they may change on every deploy and must be revalidated.
# Building, previewing, and generating
nuxt build # client + server build into .output/
nuxt preview # boots .output/server/index.mjs locally to verify the artifact
nuxt generate # build plus full prerender, for the static preset
nuxt preview is worth running before every deploy. It executes the built server rather than the dev server, so SSR-only failures, missing environment variables, and preset mismatches surface locally instead of in production. A build that previews cleanly has already been proven to start.
b. Nitro presets and the platforms they target
The preset is set through the nitro.preset key in nuxt.config.ts, or through the NITRO_PRESET environment variable, which lets the same repository produce a different artifact per CI job without editing the config.
// nuxt.config.ts โ pin the preset for a Node.js container deployment
export default defineNuxtConfig({
nitro: {
preset: 'node-server', // emits a long-lived Node HTTP server entry point
compressPublicAssets: true // pre-compress static assets with gzip and brotli
}
})
node-server is the baseline and the reference implementation. The output is an ordinary Node HTTP server started with node .output/server/index.mjs, listening on PORT and HOST. It is the correct target whenever you control a container: Docker, a VPS, a Kubernetes pod, or a traditional PaaS. It has no cold start and no bundle size limit beyond memory.
# Dockerfile โ multi-stage build for node-server
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci # install exact dependencies from the lockfile
COPY . .
RUN npm run build # produces .output/ with the node-server preset
FROM node:22-alpine
WORKDIR /app
COPY --from=build /app/.output ./.output # ship only the built artifact, not source
ENV PORT=3000
CMD ["node", ".output/server/index.mjs"] # start the real server
The static preset produces no server at all. Every route is rendered to HTML during nuxt generate, and the output is a directory of files. It is the right choice for a marketing site, a documentation portal, or any application whose data does not change per request โ and it is the wrong choice the moment a route needs a session, a POST handler that mutates state, or per-request personalization.
// nuxt.config.ts โ fully static output
export default defineNuxtConfig({
nitro: {
preset: 'static', // prerender everything, emit no server
prerender: {
crawlLinks: true, // follow internal links from the entry routes
routes: ['/'] // explicit starting points for the crawler
}
}
})
Serverless presets sit between the two. vercel compiles handlers into Vercel’s function format, netlify targets Netlify Functions, and cloudflare-pages and cloudflare-module target workerd. The edge presets are the strictest: they reject Node built-ins such as fs, path, and crypto unless you import the node: prefixed compat modules, because the workers runtime does not provide them.
// nuxt.config.ts โ Cloudflare Pages edge deployment
export default defineNuxtConfig({
nitro: {
preset: 'cloudflare-pages', // targets the workerd runtime
// Edge workers have no filesystem; anything touching fs must be polyfilled
// or moved behind an API route that runs in a compatible context
}
})
The practical rule is mechanical. If the application holds long-lived in-memory state โ a websocket registry, an in-process cache, an expensive client initialized once โ use node-server. If it has no server-side state at all, use static. If it is stateless and needs to scale to zero, use whichever serverless preset matches the host.
c. Runtime configuration, environment variables, and verification
runtimeConfig is the contract between the build and the deployment. Anything declared under its top level is server-only and never reaches the browser; anything under public is serialized into the payload and visible to every client.
// nuxt.config.ts โ declare the shape, supply no values
export default defineNuxtConfig({
runtimeConfig: {
databaseUrl: '', // server-only; never sent to the browser
apiSecret: '', // server-only; injected at startup
public: {
apiBase: '/api', // shipped to the client in the HTML payload
siteName: 'My App' // safe default for a public value
}
}
})
At startup, Nitro reads environment variables with the NUXT_ prefix and maps them onto the config tree. The mapping is mechanical: uppercase the key, replace camelCase boundaries with underscores, and prefix with NUXT_. A nested key becomes an underscore-separated path.
# Environment variables are mapped onto runtimeConfig at startup
NUXT_DATABASE_URL=postgres://... # โ runtimeConfig.databaseUrl
NUXT_API_SECRET=abc123 # โ runtimeConfig.apiSecret
NUXT_PUBLIC_API_BASE=https://api.x # โ runtimeConfig.public.apiBase
NUXT_PUBLIC_SITE_NAME='Store' # โ runtimeConfig.public.siteName
The order of operations is the whole reason this exists, and it is where most deployment bugs come from. The server bundle is built before it is deployed. On a serverless platform, the deploy and the build are often the same step, and the runtime environment is not available during the build. A value read with process.env.X at the top of a module is therefore frozen into the artifact, while a value read through useRuntimeConfig() is resolved per request. The second form is the one that survives promotion between environments.
// server/api/status.ts โ read config per request, not per module
export default defineEventHandler((event) => {
const config = useRuntimeConfig(event) // resolves against the current environment
return {
hasSecret: Boolean(config.apiSecret), // true only if the env var was set at startup
apiBase: config.public.apiBase // public values are safe to echo back
}
})
A health endpoint that reports which variables resolved is not optional on serverless. It costs one route and it answers the question “is this deployment misconfigured” without reading logs, which on a cold function may not be flushed yet.
# The full deployment cycle, for any preset
NITRO_PRESET=vercel nuxt build # build for the target runtime
nuxt preview # start the artifact locally and confirm it boots
ls -la .output/public/_nuxt # verify content-hashed assets exist
Once the artifact boots and the health endpoint reports the expected configuration, the remaining work is platform configuration: the build command, the output directory, the Node version, and the cache headers for public/_nuxt/*. Those are static answers per platform, which is why the same repository can ship to five hosts from the same source.
Complete Example Session
// ============================================
// PART 1: THE BASE CONFIGURATION
// ============================================
// nuxt.config.ts
export default defineNuxtConfig({
compatibilityDate: '2025-01-01', // pins Nitro behaviour to a known release
nitro: {
compressPublicAssets: true // pre-compress static assets for the CDN
}
})
// ============================================
// PART 2: THE PRESET SWITCH
// ============================================
// nuxt.config.ts โ driven by an env var so CI picks the target
export default defineNuxtConfig({
nitro: {
preset: process.env.NITRO_PRESET || 'node-server' // fallback keeps local dev simple
}
})
// ============================================
// PART 3: RUNTIME CONFIG DECLARATION
// ============================================
// nuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
databaseUrl: '', // server-only, supplied by NUXT_DATABASE_URL
public: {
apiBase: '/api', // client-visible default
siteName: 'My App' // overridden by NUXT_PUBLIC_SITE_NAME
}
}
})
// ============================================
// PART 4: THE HEALTH ENDPOINT
// ============================================
// server/api/health.ts
export default defineEventHandler(() => {
const config = useRuntimeConfig() // read the resolved values
return {
ok: true,
dbConfigured: Boolean(config.databaseUrl), // false means the env var was missing
site: config.public.siteName // confirms the public override landed
}
})
// ============================================
// PART 5: AN API ROUTE THAT USES THE SECRET
// ============================================
// server/api/report.ts
export default defineEventHandler(async () => {
const { databaseUrl } = useRuntimeConfig() // never read process.env at module top level
if (!databaseUrl) {
throw createError({ statusCode: 503, statusMessage: 'Database not configured' })
}
return { source: 'configured' } // the secret never leaves the server
})
// ============================================
// PART 6: THE STATIC PRESET FOR A MARKETING SITE
// ============================================
// nuxt.config.ts
export default defineNuxtConfig({
nitro: {
preset: 'static', // prerender everything, ship no server
prerender: {
crawlLinks: true, // discover routes by following internal links
routes: ['/', '/pricing'] // explicit entry points for the crawler
}
}
})
// ============================================
// PART 7: PLATFORM CONFIGURATION, THE SHAPE THEY SHARE
// ============================================
// The keys differ per host; the values are the same everywhere
{
"buildCommand": "npm run build", // runs nuxt build with the preset pinned
"outputDirectory": ".output/public", // the static half of the artifact
"installCommand": "npm ci" // exact install from the lockfile
}
# ============================================
# PART 8: THE CONTAINER TARGET
# ============================================
FROM node:22-alpine
WORKDIR /app
COPY --from=build /app/.output ./.output # only the artifact, never the source tree
ENV NODE_ENV=production # enables production code paths in the bundle
ENV PORT=3000
EXPOSE 3000
CMD ["node", ".output/server/index.mjs"] # the node-server preset entry point
# ============================================
# PART 9: THE DEPLOY SEQUENCE
# ============================================
export NUXT_DATABASE_URL="postgres://prod" # supplied at runtime, not baked in
export NUXT_PUBLIC_SITE_NAME="Production"
node .output/server/index.mjs & # start the built artifact
curl -s localhost:3000/api/health # confirm configuration resolved
// ============================================
// PART 10: THE PACKAGE SCRIPTS
// ============================================
{
"scripts": {
"build": "nuxt build", // client + server into .output/
"build:static": "nuxt generate", // full prerender, no server
"build:edge": "NITRO_PRESET=cloudflare-pages nuxt build",
"preview": "nuxt preview" // boot the real artifact locally
}
}
The ten parts moved from a base config and the preset switch, through runtime config and two API routes, into the static preset, platform configuration, a container build, the deploy sequence, and the scripts that tie each target to a command.
Quick Reference
The Output Directory
| Path | Contents | Cacheable |
|---|---|---|
.output/public/ | Static client assets | Yes, long-lived |
.output/public/_nuxt/ | Hashed JS and CSS chunks | Yes, immutable |
.output/server/ | Nitro server bundle | No, executed |
.output/server/index.mjs | Preset entry point | No |
.output/nitro.json | Build metadata | No |
Presets and Runtimes
| Preset | Runtime | Server |
|---|---|---|
node-server | Node.js process | Long-lived |
static | Any file host | None |
vercel | Vercel Functions | Serverless |
netlify | Netlify Functions | Serverless |
cloudflare-pages | workerd | Edge |
cloudflare-module | workerd | Edge |
Runtime Config Mapping
| Variable | Config Path | Visible To |
|---|---|---|
NUXT_DATABASE_URL | runtimeConfig.databaseUrl | Server only |
NUXT_API_SECRET | runtimeConfig.apiSecret | Server only |
NUXT_PUBLIC_API_BASE | runtimeConfig.public.apiBase | Server and client |
NUXT_PUBLIC_SITE_NAME | runtimeConfig.public.siteName | Server and client |
Build Commands
| Command | Result |
|---|---|
nuxt build | Client and server into .output/ |
nuxt generate | Full prerender, static output |
nuxt preview | Boot the built server locally |
NITRO_PRESET=x nuxt build | Build for a specific runtime |
Best Practices
โ Do This:
// Read config inside the handler, not at module scope
const config = useRuntimeConfig(event) // โ
// Keep secrets out of the public namespace
runtimeConfig: { apiSecret: '' } // โ
// Pin the preset in the build script per target
"build:edge": "NITRO_PRESET=cloudflare-pages nuxt build" // โ
// Prerender routes explicitly on static builds
prerender: { routes: ['/', '/pricing'] } // โ
// Preview the real artifact before deploying
nuxt preview // โ
// Serve public/_nuxt with immutable caching
Cache-Control: public, max-age=31536000, immutable // โ
// Ship only .output in the container image
COPY --from=build /app/.output ./.output // โ
โ Don’t Do This:
// Read env vars at module top level
const key = process.env.API_SECRET // โ frozen at build
// Put a secret under public
runtimeConfig: { public: { secret: '' } } // โ ships to the browser
// Deploy a route that needs fs to an edge preset
import { readFileSync } from 'fs' // โ no filesystem in workerd
// Send every request to the server on a CDN host
// (static assets bypass the CDN entirely) // โ
// Assume a serverless function holds state between requests
let cache = {} // โ resets on every cold start
// Use the dev server as a deployment check
nuxt dev // โ never exercises the built path
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Config is empty in production | Read from process.env at build time | Use useRuntimeConfig() in handlers |
| Secret appears in page source | Declared under runtimeConfig.public | Move it to the top level |
| 500 on an edge worker | Imported a Node built-in | Use node: compat modules or move the logic |
| Static deploy serves 404s | Routes not prerendered | Add them to prerender.routes |
| API routes hit the CDN | No server rewrite configured | Route the API prefix to the function |
| Cold starts breach SLA | Large server bundle | Tree-shake and audit module imports |
| Stale assets after deploy | Unhashed file cached | Only cache _nuxt/ immutably |
| Build works, preview fails | Env var missing at startup | Supply it in the runtime environment |
Real-World Examples
1. Pinning the Node preset
nitro: { preset: 'node-server' } // explicit beats implicit for containers
2. Per-CI target selection
NITRO_PRESET=netlify npm run build // same repo, different artifact
3. Declaring a server-only secret
runtimeConfig: { stripeKey: '' } // overridden by NUXT_STRIPE_KEY at startup
4. Exposing a public value
runtimeConfig: { public: { apiBase: '/api' } } // visible in the HTML payload
5. Health check endpoint
export default defineEventHandler(() => ({ ok: true }))
6. Static prerender list
nitro: { prerender: { routes: ['/', '/docs'] } }
7. Compressed assets
nitro: { compressPublicAssets: true } // gzip and brotli at build time
8. Edge preset build
NITRO_PRESET=cloudflare-pages nuxt build
9. Container entry point
node .output/server/index.mjs // the node-server wrapper
10. Verifying an artifact
nuxt preview // starts the built server, not the dev server
Visual
The Build Pipeline
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ nuxt build โ
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Client build โ โ Server build โ โ
โ โ (Vite) โ โ (Nitro) โ โ
โ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โ
โ โ โ โ
โ โผ โผ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ .output/ โ โ .output/ โ โ
โ โ public/ โ โ server/ โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ
โ Preset decides the shape of server/ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Preset Decision
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DOES THE APP HOLD STATE BETWEEN REQUESTS? โ
โ โ โ
โ YES โ NO โ
โ โโโโโโดโโโโโ โ
โ โผ โผ โ
โ node-server DOES IT NEED A SERVER AT ALL? โ
โ (container) โ โ
โ YES โ NO โ
โ โโโโโโดโโโโโ โ
โ โผ โผ โ
โ vercel/netlify static โ
โ cloudflare (files only) โ
โ (stateless) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Runtime Config Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ BUILD TIME STARTUP TIME โ
โ โ
โ runtimeConfig {} โโโโบ NUXT_DATABASE_URL โ
โ (shape) NUXT_API_SECRET โ
โ โ โ
โ โผ โ
โ useRuntimeConfig(event) โ
โ โ โ
โ โผ โ
โ resolved per request โ
โ โ
โ process.env.X at build โ frozen in the bundle โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Cache Boundary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ REQUEST โ
โ โ โ
โ โผ โ
โ /_nuxt/*.js โโโบ CDN โโโบ immutable, 1 year โ
โ โ
โ /api/* โโโบ server function โโโบ no cache โ
โ โ
โ /page โโโบ server render โโโบ revalidate โ
โ โ
โ Wrong split = slow site or broken routes โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Server engine | Nitro |
| Output directory | .output/ |
| Static half | .output/public/ |
| Server half | .output/server/ |
| Preset key | nitro.preset |
| Preset env var | NITRO_PRESET |
| Baseline preset | node-server |
| Static preset | static |
| Config API | useRuntimeConfig() |
| Env prefix | NUXT_ |
| Local verification | nuxt preview |
Key takeaways:
.output/has two halves with opposite caching rules.public/_nuxt/is content-hashed and cacheable forever; the server half is executed per request and must never be cached. Getting that split wrong produces either a slow site or broken routes.- The preset chooses the runtime, not the code.
node-server,static,vercel,netlify, and the Cloudflare presets compile the same source into different artifacts, and switching is a config value rather than a rewrite. - Use
staticonly when nothing is per-request. Prerendering is the cheapest possible deployment, and it is unusable the moment a route needs a session, a mutation, or personalization. - Edge presets forbid Node built-ins.
fs,path, andcryptoare absent in workerd, so any handler that touches them must move or be replaced with a compatible module. runtimeConfigis the only correct way to inject secrets. A serverless bundle is built before it is deployed, soprocess.env.Xread at module scope is frozen into the artifact whileuseRuntimeConfig()resolves per request.- Preview the artifact before deploying.
nuxt previewboots the built server, which is the only local check that exercises the same code path production will run.
Remember: Deployment in Nuxt is not a set of platform-specific procedures โ it is one build with a preset switch. Decide whether the application holds state, needs a server at all, and whether it can run without a filesystem; those three answers select the preset. Then route every environment-specific value through runtimeConfig so the artifact stays portable, verify the built server with nuxt preview, and let the platform configuration do nothing but point at .output/.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!