Next.js
All of Next.js — pages, API routes and the database — in one app from Git.
Next.js with server-side rendering and API routes runs as a single app: frontend and backend in one process.
Launch
- “New resource” → “App”, the repository link.
- Plan — Small or larger: 512 MB is not enough to build Next.js.
- The first deploy starts by itself; the build log is in the “Deploy” tab.
The platform detects Node.js by package.json and runs:
npm ci(ornpm installwithoutpackage-lock.json);npm run build, i.e.next build;npm start, i.e.next start.
Make sure package.json has both scripts:
{
"scripts": {
"build": "next build",
"start": "next start"
}
}
Port
The platform passes the port in the PORT variable, and next start reads it by itself (3000 by default). Nothing to configure.
Variables
Everything is set in the “Variables” tab.
NEXT_PUBLIC_…are substituted at build time and are visible in the browser. Values may contain only Latin letters, digits and URL characters, with no quotes, spaces,$or backslashes. After changing them you need a new deploy.- Other variables (
DATABASE_URL, API keys) are read at run time in server code and API routes. They do not require a new build.
API routes and the database
API routes run in the same app; no separate backend needed. For a database, create a managed PostgreSQL or MySQL, and in the database's “Connection” tab choose the app → “Connect”. The connection string arrives in DATABASE_URL and is updated automatically when the password changes. More in Managed databases.
// app/api/items/route.js
import { Pool } from 'pg';
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export async function GET() {
const { rows } = await pool.query('select * from items');
return Response.json(rows);
}
User uploads
Every deploy starts from a clean disk. Keep files uploaded by users on a persistent volume (for example /app/data, “Settings” tab) or in external S3 storage, such as MinIO from the catalog.
Sleep
In the “Settings” tab you can enable sleep without visitors: while nobody opens the site you pay 25% of the plan, and the first visitor wakes it up in a few seconds.
Separate frontend
If the frontend and the API are in different repositories, see Frontend, backend and database from separate repositories.