BlogNext.js

How to deploy a Next.js app with a backend and database.

A Next.js app runs as a server on Antideploy. Here is what is detected, how the database and migrations work, and what breaks builds.

How the Agent API works
  • next buildRun as your build script
  • next startRun as your start script
  • PostgresWith Prisma or Drizzle migrations
  • Build-time trapsVariables and import-time code

The short answer

To deploy a Next.js app with a backend and a database, give your coding agent the sentence below. Antideploy detects Next.js, runs your build script, starts the app with your start script or next start, and treats it as an app with a server. If your code needs Postgres, it creates a database and sets DATABASE_URL. A Next.js app counts as one live app on your plan.

Say this to your coding agent

Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.

What Antideploy detects

  • Next.js. Detected from the next dependency. Nuxt, SvelteKit, Remix, Astro and Gatsby are detected the same way.
  • Build and start. It runs npm run build when you have a build script. It starts with npm run start, or next start when there is no start script.
  • The port. It starts the app with PORT set. Next.js reads it on its own.
  • The package manager. It follows your lock file: npm ci for a package-lock.json, and pnpm or yarn with a frozen lock file.
  • The database. A Prisma datasource, Drizzle config or Postgres driver means Postgres. Antideploy creates one and sets DATABASE_URL.

Migrations

Prisma runs npx prisma migrate deploy when you have a migrations folder, and npx prisma db push when you do not. Drizzle runs npx drizzle-kit migrate. The command runs after the build and before the new version goes live. If it fails, the deploy fails and the broken schema is never released.

Prisma 7 removed the url field from the datasource block. If you see an error about it, pin prisma and @prisma/client to version 6 in package.json, or move the connection string into prisma.config.ts.

What breaks Next.js builds

Next.js runs each route's module while it builds. Anything that throws as soon as a file is loaded takes the build down with it.

  • A variable that is not set during the build. Secrets you save on Antideploy are available when the app runs, not while it builds. Give the value a fallback, or read it inside the handler instead of at the top of the file. See Failed to collect page data.
  • A database call at import time. Opening a connection or running a query at the top of a file runs during the build. Move it inside the handler.
  • A type error. Type errors fail the build even when the app runs locally with next dev. See TypeScript errors fail the build.
  • NEXT_PUBLIC_ variables. These are copied into the built files, so they must be set before the build. Never put a secret in one, because anyone who loads the site can read it.

Step by step

  1. Run the build on your machine first

    npm run build should pass locally. If it fails, the deploy will too.

  2. Paste the sentence and approve one link

    Your agent creates the app, and a database if your code needs one, and writes the connection details into your .env without printing them.

  3. Deploy and open the link

    Antideploy installs, builds, runs your migration, starts the app and checks that it answers. Your agent tells you the address.

Sign-in and uploads

Antideploy can switch on sign-in for your app's users. In Next.js, you install Neon's auth library and follow Neon's quickstart, and the variables it needs are already set. Uploads should go to a bucket, never to the app's disk. See add login and add file uploads.

01Before you commit

Here's where it stops.

A platform that only tells you what it is good at is one you find the edges of in production. These are the ones to know before your first deploy.

  1. Apps sleep when idle

    On every plan, an app nobody is using goes to sleep and the next visit wakes it. The first request took 2.9 to 13.9 seconds in our measurements, depending on the stack. There are no always-on workers, so use a cron job or a webhook for background work.

  2. One instance, no previews

    Each app is one instance with 1 shared vCPU and 1 GB of memory, and a Java app gets 1 dedicated vCPU and 2 GB. There are no preview deployments and no per-branch URLs.

  3. The disk forgets

    Anything written to local disk is gone on the next deploy. Apps that speak S3 get a bucket instead.

02Questions

Next.js questions, answered.

Anything else? Write to us and a person answers.

support@antideploy.com
Does Next.js need a Dockerfile?

No. Antideploy builds it from your project. If there is a Dockerfile at the root, it is used instead.

Is a Next.js app free to host here?

It runs on the Free plan, which includes 1 live app with a server, 10 successful deploys a month and 1 Postgres database. Failed deploys are free.

Does it support API routes and server actions?

Yes. The app runs as one long-running server, so API routes and server code work as they do locally.

Why is the first visit slow?

Apps sleep when idle. The first request after sleeping took 2.9 to 13.9 seconds in our measurements, depending on the stack, and Next.js was the slowest stack we measured.

Which Node.js version does it use?

The one in engines.node, a .nvmrc or a .node-version file. If none is set, the builder picks one.

Deploy something. Start with one sentence.

Paste one sentence into your coding agent, click Approve once, and get a live link. No card, no trial clock.

Start from GitHub or a folder
Prompt copied Paste it into Claude Code, Codex or Cursor and press Enter.