Deploy Next.js with Postgres and Prisma
This guide deploys a Next.js App Router app to Naijacloud with a managed Postgres database. At the end you’ll have a small notes app at your own naijacloud.app address that saves to Postgres through Prisma, with migrations applied every time a new version starts and every push to your branch deploying automatically. The stack is Next.js 16, Prisma 7 with the pg driver adapter, and Postgres 18, deployed from a GitHub repository.
nextjsprismapostgresA Next.js notes app on your own naijacloud.app address. Type a note, press Save, and it’s written to Postgres and read back on every request.
Before you start
- A Next.js app in a GitHub repository, with its
package-lock.jsoncommitted. Starting fresh? Runnpx create-next-app@latestand push it. - Node.js 20 or newer on your machine, and Docker if you want a Postgres to develop against.
- A Naijacloud account. The free tier covers this guide: one web service and one database.
Add Prisma
Install the Prisma CLI, the client and the driver adapter for pg. Prisma 7 talks to Postgres through the adapter rather than its own engine.
Create the schema. The client is generated into app/generated/prisma, so add that folder to .gitignore: it’s rebuilt on every build.
Prisma 7 reads the connection string from prisma.config.ts, not from the schema:
Create the first migration
Run a Postgres locally and create the migration against it. The migration files are what Naijacloud applies to the real database later, so commit them.
Then make npm run build generate the client before Next.js builds, in package.json:
Read and write from a page
Create one Prisma client for the whole process:
Then a page that lists notes and saves new ones with a server action. await connection() keeps the query at request time, so the build never needs the database.
Create the database
In the dashboard, open your project and choose New service → Database. Name it notes-db, pick Postgres, choose the Free size and click Create database. On the notes-db is ready. screen, click Reveal secrets and copy the Internal URL. The password is shown once on this page.
Create the web service
Choose New service → Web service, name it notes and, under Source, pick your repository and branch on the GitHub tab. Naijacloud detects Next.js and fills in npm ci && npm run build and npm start. Keep the build command and change the start command so migrations run first:
npm ci && npm run buildnpx prisma migrate deploy && npm startUnder Environment variables, click + Add variable and add one:
Leave the size on Free and click Create web service. Free apps may sleep when nobody visits for a while and wake on the next request; paid apps never sleep.
Deploy and try it
Open the service. The Deploys tab streams the build; when it goes live, the runtime log shows the migration and Next.js starting:
Open https://notes.naijacloud.app, write a note and press Save. It’s in Postgres: reload the page and it’s still there. Every push to your branch now builds, migrates and goes live.