Nuxt

Deploy a Nuxt app

Run your Nuxt app in production as a server with its own database, so pages render on each request and server routes can query PostgreSQL. This guide covers the Nitro output, runtime config and deploying it on Modelence.

Last updated /Tested with Nuxt 4.7 and Node.js 22

To deploy a Nuxt app, run nuxt build, which writes a standalone Node.js server to .output, start it with node .output/server/index.mjs and pass its settings as NUXT_ environment variables. On Modelence you describe the app in modelence.config.json and deploy it with one command. Modelence builds it on an official Node.js image, runs it as containers on AWS in the region you pick out of 17 and creates the MongoDB, PostgreSQL and Redis databases it needs in the same region.

This guide deploys a Nuxt 4 app as a server, the way nuxt build produces it, so pages render on each request and server routes in server/ read and write a managed PostgreSQL database. A static export from nuxt generate has no server, so it can't run those routes or fetch fresh data for each visitor. If you already have a Nuxt app, skip to Run the app locally.

Nuxt on Modelence at a glance

Start command
node .output/server/index.mjs after npm ci and npm run build, on the official node-22-slim image
Rendering
Pages render on the server for each request, and routeRules can prerender or cache single routes
Configuration
NUXT_ variables override runtimeConfig when the server starts, so one build runs in every environment
Health check
A new container takes traffic only once a route such as /health answers 2xx within 4 seconds
Regions
17 AWS regions, with the app, its databases and their backups in the one you pick
Databases
Managed MongoDB, PostgreSQL and Redis in the app's region over TLS, with production data backed up at least every 6 hours
Logs
Server-side errors and everything the server writes to stdout show on the environment's Logs page
Price
Free plan to start, and paid plans from $20 a month with the $20 included as usage

Before you start

  • Node.js 22.22 or 24.15 or newer, which Nuxt 4.7 needs, and npm
  • A Modelence account, which you can create for free
  • Optionally, Claude Code, Cursor or Codex, if you'd rather have your coding agent write the config and run the deploy

Create a Nuxt app

Create a project from the minimal template:

npm create nuxt@latest my-app -- --template minimal --packageManager npm
cd my-app

Then declare the settings the server needs in runtimeConfig in nuxt.config.ts. Each key gets an empty or default value here, and the deployed app sets the real one through an environment variable named after the key: databaseUrl becomes NUXT_DATABASE_URL, and public.siteName becomes NUXT_PUBLIC_SITE_NAME. Keys at the top level stay on the server, while keys under public also reach the browser, so connection strings and API keys never go under public.

nuxt.config.ts
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2025-07-15',
  devtools: { enabled: true },
  runtimeConfig: {
    // Server only. Set at runtime by NUXT_DATABASE_URL.
    databaseUrl: '',
    public: {
      // Also sent to the browser. Set at runtime by NUXT_PUBLIC_SITE_NAME.
      siteName: 'My app',
    },
  },
})

Add server routes that use the database

Code in server/ runs only on the server, so that is where the app talks to its database. Install the PostgreSQL client with npm install pg, and add server/utils/db.ts, which creates one connection pool per server process from the runtime config. Nuxt imports functions from server/utils automatically in every server route:

// server/utils/db.ts
import pg from 'pg'

let pool: pg.Pool | undefined

export function useDb() {
  pool ??= new pg.Pool({ connectionString: useRuntimeConfig().databaseUrl })
  return pool
}

A file in server/api becomes an API route. createError sets the status code, and Nuxt sends the error as JSON:

// server/api/items/[id].get.ts
export default defineEventHandler(async (event) => {
  const id = Number(getRouterParam(event, 'id'))
  if (!Number.isInteger(id)) {
    throw createError({ statusCode: 400, statusMessage: 'Invalid item id' })
  }
  const { rows } = await useDb().query('SELECT id, name FROM items WHERE id = $1', [id])
  if (rows.length === 0) {
    throw createError({ statusCode: 404, statusMessage: 'Item not found' })
  }
  return rows[0]
})

Add server/api/items/index.get.ts the same way, returning all rows. A page then loads the data with useFetch, which calls the route directly while the page renders on the server, so the HTML arrives with the items already in it. Replace the welcome screen in app/app.vue with <NuxtPage />, so it renders the files in app/pages:

app/pages/index.vue
<script setup lang="ts">
const { siteName } = useRuntimeConfig().public
const { data: items } = await useFetch('/api/items')
</script>

<template>
  <main>
    <h1>{{ siteName }}</h1>
    <ul>
      <li v-for="item in items" :key="item.id">{{ item.name }}</li>
    </ul>
  </main>
</template>

Run the app locally

Put the local values in .env, which nuxt dev reads, and start the development server:

echo 'NUXT_DATABASE_URL=postgres://localhost:5432/my_app' > .env
npm run dev

Then open http://localhost:3000.

You can also connect the project to a Modelence local environment, so the app runs on your machine with the environment's database connection strings and variables, and they never need to be copied into a .env file. npx modelence@latest setup opens the browser, where you sign in and pick or create an app and environment. After that, start the app with npx modelence@latest dev instead of npm run dev. It runs your dev script with the environment's variables, and the environment's Overview in the dashboard shows the app while it runs.

bash
npx modelence@latest setup
npx modelence@latest dev

Add a database

  • MongoDBMONGODB_URI
  • PostgresDATABASE_URL
  • RedisREDIS_URL

A Nuxt app reaches Modelence's managed MongoDB, PostgreSQL and Redis from its server routes, through connection strings in environment variables. The databases run in the app's region, connections use TLS and production data is backed up at least every six hours.

You choose the variable names in modelence.config.json, so tie the database's URL straight to NUXT_DATABASE_URL and read it with useRuntimeConfig().databaseUrl, as server/utils/db.ts does. Reading process.env in nuxt.config.ts doesn't work for this, because that file runs during the build, before the deployed environment's variables exist.

Drizzle, Prisma, the MongoDB driver and Redis clients follow the same pattern: one client per server process, created in server/utils and used only in server/. A database you keep on Supabase or Neon needs no code changes either, and its URL goes in env with "type": "secret".

Run migrations, whether from Drizzle Kit, Prisma or your own SQL files, against the environment's database before you deploy rather than in the start command or a Nitro plugin. Every container runs them, and a rollout starts several at once.

Declaring a PostgreSQL database or a Redis cache takes a few lines in modelence.config.json, and the deploy creates it before the new version of the app starts:

modelence.config.json
{
  "resources": {
    // "web": the Nuxt service, as in the next step
    "main-db": { "type": "postgres", "plan": "postgres-1gb" },
    "cache": { "type": "redis" }
  },
  "env": {
    "NUXT_DATABASE_URL": { "type": "resource", "resource": "main-db", "output": "url" },
    "NUXT_REDIS_URL": { "type": "resource", "resource": "cache", "output": "url" }
  }
}

Describe the app in modelence.config.json

Modelence builds a Nuxt app as a Node.js service. It runs your build commands on an official Node.js image, here npm ci and npm run build, then starts the Nitro server that nuxt build wrote to .output/server/index.mjs. Nitro reads the port from PORT, listens on every interface and serves the files in .output/public itself, with a one year cache on the hashed ones in /_nuxt/. The file also turns on the HTTP health check, creates the PostgreSQL database and ties its URL to NUXT_DATABASE_URL. Add modelence.config.json at the root of the repository and commit it with the app:

modelence.config.json
{
  "$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
  "resources": {
    "web": {
      "type": "service",
      "image": "node-22-slim",
      "build": { "commands": ["npm ci", "npm run build"] },
      "start": { "commands": ["node .output/server/index.mjs"] },
      "healthCheck": { "type": "http", "path": "/health" }
    },
    "main-db": { "type": "postgres", "plan": "postgres-1gb" }
  },
  "env": {
    "NUXT_DATABASE_URL": { "type": "resource", "resource": "main-db", "output": "url" },
    "NUXT_PUBLIC_SITE_NAME": { "value": "My app" }
  }
}

Adjust the config for your project

  • npm ci also runs nuxt prepare from the project's postinstall script. With pnpm, use corepack enable && pnpm install --frozen-lockfile and pnpm build.
  • nuxt build uses Nitro's node-server preset unless something else sets one, so leave nitro.preset unset or set it to node-server.
  • Start the server with node, not with nuxt preview or nuxt dev.
  • NUXT_ variables only override keys that exist in runtimeConfig, so add a key there for every variable you set.
  • Declare keys and tokens with "type": "secret" and no value, under their NUXT_ names. The deploy asks you for them in the browser, and you can change them later in the dashboard under Environment variables, where every view of a secret is logged.
  • If the app lives in a subdirectory of a monorepo, set root on the service.

Check the build locally

Before the first deploy, run the same commands Modelence will run, in the same order, then check the health route from a second terminal. The server reads .env only in development, so pass the database URL on the command line. A deploy runs the same build, so anything that fails here fails there too.

bash
npm ci && npm run build
NUXT_DATABASE_URL=postgres://localhost:5432/my_app PORT=3000 node .output/server/index.mjs

# in a second terminal
curl http://localhost:3000/health

Deploy

Run the deploy command in the project directory:

npx modelence@latest deploy

It opens the browser, where you sign in, pick the organization, app and environment (or create them) and enter any required variables the environment doesn't have yet. Then it uploads the project and follows the build until the app is live. You pick the AWS region the first time you deploy an environment, and its containers and databases are created there. Next time, pass --app <app> --env <env> to preselect the target.

The first deploy creates the database, starts the server once it's ready and attaches the environment's URL, <app>-<environment>.cloud.modelence.app, to the web service. To use your own domain, add it in the dashboard under Domains. Every app has a sandbox and a production environment, and the same file deploys to both, each with its own database and its own values for the NUXT_ variables.

Let your coding agent do it

Paste Deploy using https://modelence.com/skill.md into Claude Code, Cursor or Codex in your project. The agent reads the docs, writes modelence.config.json for your project, checks the build and runs the deploy, and it stops to ask you whenever a step needs your account.

Production readiness

Add a health route

By default Modelence counts a container as healthy once it accepts connections on its port. With "healthCheck": { "type": "http", "path": "/health" }, the route has to answer with a 2xx status within 4 seconds, so a new version that starts but can't reach its database never takes traffic and the deploy rolls back. A file in server/routes becomes a route without the /api prefix:

// server/routes/health.get.ts
export default defineEventHandler(async () => {
  await useDb().query('SELECT 1')
  return { status: 'ok' }
})

If the query fails, Nitro answers with a 500. Keep authentication middleware in server/middleware from blocking this path.

Run it as a server, and prerender what can be static

nuxt generate writes HTML for the routes it can find at build time, and the result has no server. Server routes don't exist there, useFetch data is frozen at build time and pages behind a login can't check the session. Deployed as a server, every page renders with fresh data and the same deploy runs the API.

Pages that rarely change can still be static. routeRules in nuxt.config.ts prerenders single routes at build time with { prerender: true } or caches the rendered HTML for a while with { swr: 600 }, and the rest of the app keeps rendering on each request.

Keep runtime settings in runtimeConfig

Values in runtimeConfig are read when the server starts, so the same build runs in the sandbox and production environments with different variables. Values written into the code at build time, such as import.meta.env or process.env in nuxt.config.ts, need the variable during the build. Give those "scopes": ["build", "runtime"] in modelence.config.json, and keep secrets out of them, since they can end up in the browser bundle.

Close the database pool on shutdown

When a container stops, it gets SIGTERM and 30 seconds before SIGKILL. Nitro handles the signal itself: it stops accepting connections, waits for open requests and calls the close hook. A Nitro plugin can end the pool there:

// server/plugins/db.ts
export default defineNitroPlugin((nitroApp) => {
  // Nitro calls the close hook when the container gets SIGTERM.
  nitroApp.hooks.hook('close', async () => {
    await useDb().end()
  })
})

Nitro waits up to 30 seconds for this by default. Set NITRO_SHUTDOWN_TIMEOUT to 20000 in env so it finishes before the container's own 30 seconds are up.

Read the visitor's address from the load balancer

Requests reach the server through Modelence's load balancer, which terminates HTTPS and adds the client's address to the end of X-Forwarded-For. getRequestIP(event, { xForwardedFor: true }) returns the first entry of that header, which a client can write itself. For rate limits or audit logs, take the last entry instead:

const ip = getRequestHeader(event, 'x-forwarded-for')?.split(',').at(-1)?.trim()

getRequestProtocol(event) already returns https, because it reads X-Forwarded-Proto.

Keep state out of the process

A container has no persistent disk and is replaced on every deploy. Keep sessions and uploads in the database or object storage, and note that Nitro keeps swr and defineCachedEventHandler results in memory, separately in each container, unless you mount its cache storage on Redis. Then raise the service to two or more containers under Configure, which keeps the app up through a crash or a zone outage.

Watch logs and metrics

Logs need no setup. Errors from server rendering and server routes, along with anything the server code writes with console.log, show on the environment's Logs page. Errors in the browser stay in the browser, so send those to an error tracker such as Sentry. For traces and metrics, add a telemetry resource and tie the standard OpenTelemetry variables to it. Deploy setup has the full example.

Modelence vs Vercel, Railway and Render for Nuxt

Vercel, Railway and Render are the platforms people compare most often for Nuxt deployment. Railway, Render and Modelence run the Nitro output as a long-running Node.js server, while on Vercel Nitro builds the server part into functions. The figures below come from each platform's own docs and pricing pages in November 2026.

PlatformHow a Nuxt app runsDatabasesPricing
Modelencenode .output/server/index.mjs as long-running containers on AWS in 17 regionsManaged MongoDB, PostgreSQL and Redis, backed up at least every 6 hoursFree plan, then from $20 a month with $20 of usage included
VercelNitro's Vercel preset, with server rendering and server routes as Vercel Functions in 1 region by default and assets on the CDNPostgres, Redis and others through Marketplace providers such as Neon and UpstashHobby is free for personal, non-commercial use; Pro is $20 per developer seat a month with $20 of credit
RailwayA Node.js service with the build and start commands you set, or your Dockerfile, in 4 regionsPostgres, MySQL, Redis and MongoDB templates, with backups you turn onHobby $5 or Pro $20 a month including that much usage, then compute billed by the second
RenderA Node web service in 5 regions, with the build and start commands you set, or a static site for nuxt generateManaged Postgres from $6 a month, Redis-compatible Key Value from $10 a monthWorkspace plan ($0, $25 or $499 a month) plus a fixed price per instance, from $7 a month

Vercel works well for a Nuxt site whose server routes are short and stateless, and its preview deployments for every pull request suit content-heavy sites. An app that holds WebSocket connections, uses Nitro tasks or keeps a connection pool open fits a platform that runs a server better. Railway is the quickest way from a repository to a running app, and Render's fixed instance prices are easy to budget for steady traffic. Modelence fits when the Nuxt server and its MongoDB, PostgreSQL or Redis should run together on AWS in a region you choose, with failed deploys rolled back for you. For more detail, see Modelence vs Vercel and Railway vs Render.

Next steps

Frequently asked questions

How do I deploy a Nuxt app to production?

Run nuxt build, which writes a standalone Nitro server to .output, and start it with node .output/server/index.mjs on a platform that keeps the process up. Pass its settings as NUXT_ environment variables that match keys in runtimeConfig. On Modelence you put npm ci, npm run build and the start command in modelence.config.json and run npx modelence@latest deploy, and Modelence runs the server in the AWS region you pick with its database next to it.

Should I use nuxt build or nuxt generate?

Use nuxt build when the app has server routes, data that changes per request or pages behind a login, since it produces a server that renders each request. nuxt generate produces static HTML with no server, which suits a site whose content only changes when you rebuild it. With routeRules you can prerender individual routes inside a server build, so most apps don't have to choose.

What is .output/server/index.mjs?

It's the entry point of the Nitro server that nuxt build creates with the node-server preset. The .output folder holds the server code, its own node_modules with only the packages it uses, and the public files the server sends, so it runs with plain node and doesn't need the project's node_modules. It reads the port from PORT and the host from HOST, and listens on every interface when HOST isn't set.

Why are my NUXT_ environment variables ignored?

Nuxt only applies a NUXT_ variable when the matching key exists in runtimeConfig in nuxt.config.ts, so NUXT_DATABASE_URL needs a databaseUrl key, even an empty one. Read the value with useRuntimeConfig() rather than process.env in nuxt.config.ts, which runs at build time. Public keys go under runtimeConfig.public and take the NUXT_PUBLIC_ prefix.

Can I deploy a Nuxt app on Vercel?

Yes. Nitro detects Vercel and builds the server rendering and server routes into Vercel Functions, with static assets on Vercel's CDN, so the Vercel Functions limits apply to each request. If the app keeps WebSocket connections, runs Nitro tasks or should keep one database pool per process, a platform that runs the Nitro server as a long-running process, such as Modelence, Railway or Render, fits it better.

How do I connect a Nuxt app to a database?

Create the client in server/utils from a runtimeConfig key, such as databaseUrl, and use it only in server routes under server/api or server/routes. Pages and components then load the data with useFetch, which calls those routes during server rendering. On Modelence the managed MongoDB, PostgreSQL or Redis URL is tied to a NUXT_ variable in modelence.config.json, so no connection string lives in the code.

Which Node.js version does Nuxt 4 need?

Nuxt 4.7 needs Node.js 22.22 or newer in the 22 line, or 24.15 or newer. On Modelence, use the node-22-slim or node-24-slim image, or name an exact version such as node-22.23.1-slim if you want the build to stay on one release.

How much does it cost to host a Nuxt app on Modelence?

You can start on the free plan, which runs one instance that sleeps when idle. Paid plans start at $20 a month with the same $20 included as cloud usage, and they add managed PostgreSQL and Redis and more than one service. Containers are billed hourly by size, from about $9 a month for the smallest one with 0.25 vCPU and 0.5 GB of memory, and the plan price covers the whole team with no charge per seat.

Deploy other stacks

Deploy your Nuxt app

Start on the free plan and move up when your app needs more.

Or paste this into your coding agent