Documentation Frameworks and migration

Deploy a Nuxt app

nuxt build and the self-contained .output server, fitting the Free plan, and PostgreSQL.

~3 min read
On this page

Gregale deploys a Nuxt app from its source as a Node app: it installs dependencies with the package manager your lockfile names, runs your build script (nuxt build), and starts the server Nuxt builds into .output. What every framework shares is on Deploy a web framework.

The app runs as a server, so server routes, API routes and server-side rendering all work.

Prepare the app

Keep the scripts nuxi init writes. Without a start script, Gregale starts the server with node .output/server/index.mjs. A start script that is exactly that command works the same way:

json
{
  "scripts": {
    "build": "nuxt build",
    "start": "node .output/server/index.mjs"
  }
}

The server reads the PORT Gregale sets and listens on every interface, so it needs no flags. nuxt dev and nuxt preview are development commands; deploy the production server.

Plans and the app layer

A Nuxt app runs on every plan, Free included. nuxt build writes a self-contained server to .output: it bundles the dependencies it needs, so it runs without node_modules. A starter app with its full node_modules needs about 380 MB, more than the Free plan's 256 MB app layer. When the full app would not fit your plan, Gregale ships only .output and package.json (about 66 MB for a starter, most of it the guest runtime) and starts the server on Node 24. This applies when all of these hold:

  • the app starts with node .output/server/index.mjs, directly or as a start script with no prestart or poststart script;
  • nuxt build wrote .output/server/index.mjs (Nuxt's default node-server preset);
  • the app builds on Node 24, the default;
  • the deployment has no release command, which may need your sources or node_modules.

An app that fits its plan ships whole, as before. Files your server reads at runtime from outside .output are not shipped in the smaller layout; put them in public/ or server/assets/ so Nuxt copies them into .output.

See App layer and Plans and pricing.

Add PostgreSQL

bash
gregale add postgres --app my-app

The connection URL arrives as DATABASE_URL, through a connection pooler in transaction mode. With postgres.js, open the pool on first use in a server utility, and turn off prepared statements:

ts
// server/utils/db.ts
import postgres from 'postgres';

let sql: postgres.Sql | undefined;

export function db() {
  sql ??= postgres(process.env.DATABASE_URL!, { max: 5, prepare: false });
  return sql;
}

Run migrations as a release command with their own credential, which only the release command receives:

bash
gregale postgres attach my-app-postgres my-app --access migration --env MIGRATION_DATABASE_URL

A release command means the deployment ships node_modules (see Plans and the app layer), and Nuxt's build tools make that large: a small app measured 529 MB, over the Hobby plan's 512 MB. Keep runtime packages in dependencies and the rest in devDependencies, then remove the development dependencies after the build:

json
{
  "scripts": {
    "build": "nuxt build && npm prune --omit=dev"
  }
}

The server in .output bundles what it needs, so the same app measured 227 MB this way. The example repository below skips the prune in a git checkout, so local builds keep their tools.

Example repository

gregale-dev/nuxt-postgres is a Nuxt 4 notes app on this page's setup: server-rendered with useFetch, API routes in server/api/, postgres.js, and migrations as the release command. Its gregale.yaml creates the database, so one command deploys both:

bash
git clone https://github.com/gregale-dev/nuxt-postgres
cd nuxt-postgres
gregale deploy --name my-nuxt-app

Spotted a problem on this page? Tell us