Framework guide

How to deploy a Next.js app

To deploy a Next.js app on Codara Cloud, push it to GitHub with the usual next build and next start scripts, then create an app from the repository in the console. Codara detects package.json, builds with Railpack and starts your start script; next start listens on the PORT that Codara sets (8080 by default). Put server secrets in runtime environment variables; NEXT_PUBLIC values are compiled at build time, so commit them in .env.production.

By Codara Solutions · Reviewed

What does your Next.js project need?

A standard Next.js project needs no changes. Without a Dockerfile, Codara builds it with Railpack: it detects package.json, picks the package manager from your lockfile, runs your build script and starts the app with your start script. It also caches .next/cache between builds.

Commit your lockfile, and pin the Node version in package.json so the build does not change under you. next start reads the PORT environment variable and listens on all interfaces by default, so it works with the port Codara sets.

package.json
{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "engines": { "node": "22.x" }
}

Build the production version locally once with npm run build and npm start. If it only works with next dev, fix that first: the platform runs the production build.

How do you create the app on Codara Cloud?

Install the Codara GitHub App on the account that owns the repository, and create a project; it comes with a production environment. Then use the console’s deploy wizard, Apps → New app: choose the project and environment, select GitHub repository with its branch, and submit. The wizard is the only path that creates the app and starts its first build in one step.

Leave the port at 8080: Codara passes it to the container as PORT and next start uses it. The first build usually takes a few minutes. When the release is live, the app is on HTTPS at its codara.cloud address, and every push to the branch deploys a new version.

Terminal · the same from the CLI
codaracloud projects create website --client my-workspace --name "Website"

# apps create does not start a build; deploy --source does
codaracloud apps create web --client my-workspace --project website \
  --repo acme/web --branch main
codaracloud deploy web --client my-workspace --project website --source

codaracloud open web

Where do environment variables and NEXT_PUBLIC values go?

Server-only values, such as API keys and database passwords, go in the app’s runtime environment variables. They are available to server components, route handlers and middleware when the app runs, and not during the build.

Next.js compiles NEXT_PUBLIC_ variables into the browser bundle during next build, so they must exist at build time, and runtime variables do not. Because these values are public anyway, put them in a committed .env.production file, which next build reads. With the default Railpack build this is the way to set them today: build arguments set on the app do not reach a Railpack build. If you build with your own Dockerfile, you can pass them as build arguments instead: declare ARG NEXT_PUBLIC_SITE_URL and ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL before RUN next build. Never put a secret in a NEXT_PUBLIC_ variable, .env.production or a build argument.

Terminal
# Runtime values (secrets belong here)
codaracloud env set web STRIPE_SECRET_KEY=sk_live_... AUTH_SECRET=...
.env.production (committed, public values only)
NEXT_PUBLIC_SITE_URL=https://www.example.com

Should you use standalone output or a Dockerfile?

You do not need either. The default next build and next start work on Codara as they are. Standalone output (output: "standalone" in next.config) produces a smaller server that you start with node .next/standalone/server.js, but Next.js does not copy the public and .next/static folders into it for you.

If you want standalone output or full control of the image, add a Dockerfile at the root of the repository. Codara uses a root Dockerfile exactly as written, instead of Railpack. Copy public and .next/static into the standalone folder in your Dockerfile, and start server.js with PORT and HOSTNAME=0.0.0.0.

A fully static export (output: "export") has no server. Build it locally and publish the out folder with the MCP tools, or keep next start if you use server features.

How do you add a database and your own domain?

Create a Postgres database in the same environment and connect it to the app. Codara injects DATABASE_URL for your queries and DATABASE_DIRECT_URL for migrations, then restarts the app. Run migrations as a pre-deploy command so a failed migration never replaces the working release.

Add your domain to the app, create the DNS record the console shows, and Codara issues the certificate. Keep the codara.cloud address for testing.

Can your coding agent deploy it for you?

Yes. Connect Claude Code, Cursor, Codex or another MCP client to Codara with the setup prompt in the docs. Your agent can then create the project, connect GitHub, create databases and read build logs. Agent tokens are development-only by default, so publishing to production stays a separate step you approve.

Prompt for your agent
Deploy this Next.js app to Codara Cloud in a development environment of
project "website". Use codara_search to find the operations. Check that
package.json has build and start scripts, create a Postgres database and
connect it, then show me the build logs and the app URL.

Questions

Do server components, route handlers and middleware work?
Yes. Codara runs next start, the Next.js production server, as an always-on container, so server rendering, route handlers, server actions and middleware run as they do on any Node.js server.
Which port does a Next.js app use on Codara Cloud?
Codara sends traffic to port 8080 by default and sets PORT to match. next start reads PORT, so you do not need to change anything. If you set a different port on the app, PORT follows it.
Is a Next.js app cheaper on Codara Cloud than on Vercel?
It depends on your traffic and team. Codara Cloud is a fixed €5 to €100 a month per organization, with databases included; Vercel charges per deploying seat plus usage. Our comparison page works through the numbers.

Keep going