Deploy Next.js with a database in India
Deploy Next.js in India: build from Git on Plexivo App Runner in Mumbai, connect Plexivo Postgres and keep the connection string a secret.

A Next.js app is rarely only a front end. Sooner or later it has route handlers, server components that read data, and a database behind them. Hosting it well in India means three things: the app runs close to your users, the database runs beside the app, and the connection string never leaks into the browser.
This guide deploys a Next.js app on Plexivo App Runner in Mumbai, connects it to Plexivo Postgres, and shows two ways to talk to the database: plain SQL from the server, and the Plexivo Postgres Data API with sign-in and live data.
What do you need to deploy Next.js in India?
- Your code in a GitHub, GitLab or Bitbucket repository.
- A Plexivo organisation. Sign up at cloud.plexivo.io; the free trial is on the Developer plan.
- A project to hold the app and its database. Resources in the same project reach each other over the private network.
Everything runs in Mumbai, India. India (Mumbai) is live today, and more countries are available on request. Database backups are kept in Mumbai and copied to Hyderabad.
How does Plexivo App Runner build a Next.js app?
When you deploy from Git, Plexivo App Runner clones your branch, builds an image, signs it and releases it. Each build runs in its own isolated sandbox. There are two ways it can build:
- Without a Dockerfile. Plexivo detects your language and framework, installs your dependencies, builds and sets the start command. Next.js is one of the supported stacks.
- With a Dockerfile. If the repository has a Dockerfile at its root, Plexivo builds it as it is. This gives you full control over the Node.js version and the build steps.
Either way, your server must listen on the port in the PORT environment variable, on 0.0.0.0. Unless your image declares another port, it is 8080. The Next.js production server, next start, reads PORT, so a standard app needs no change. For a custom server, the documented pattern is:
const port = process.env.PORT || 8080;
app.listen(port, '0.0.0.0');A build that succeeds is not live until its instances pass their health check. Until then, the current release keeps serving. The builds page has the details.
Which database should a Next.js app use?
Plexivo Postgres is managed PostgreSQL, with PostgreSQL 18 recommended and PostgreSQL 17 available. It suits Next.js in two ways, and you can mix them:
- SQL from the server. Route handlers and server components connect with any PostgreSQL driver or ORM, using
DATABASE_URL. This is the classic setup. - The Plexivo Postgres Data API. The browser talks to the database through
@plexivo/client, with user sign-in, row-level security and Realtime. Server routes can still run raw SQL with the secret key.
The smallest Plexivo Postgres size is 0.25 vCPU, 512 MB and 10 GB for US$11.98 a month. The smallest Plexivo App Runner size is 0.125 vCPU and 256 MB for US$6.04 a month. See create your first database.
Step by step: deploy Next.js with Plexivo Postgres
- Create the database. Choose Create, then Plexivo Postgres. Enter the Database name, pick the Project, keep PostgreSQL 18, choose the Database size and Backups kept, check the Estimated monthly cost and choose Deploy.
- Start the app. Choose Create, then Plexivo App Runner, and pick the same Project.
- Connect your repository. Under Source, pick GitHub, GitLab or Bitbucket and choose Connect GitHub (or GitLab, or Bitbucket). For GitHub, install the Plexivo GitHub App and choose which repositories it may read. Then choose the Repository and Branch.
- Name and size it. The name becomes its address,
<name>.plexivo.app. Choose a size and the Minimum instances and Maximum instances. - Deploy. Check the Estimated monthly cost and choose Deploy. Follow the build on the app's Deployments tab, which lists every build with its Build status, Commit, Author, Duration and Build minutes.
- Connect the database. On the app's Environment tab, under Add a database or cache, choose the Resource and Connect. Plexivo delivers
DATABASE_URLandDATABASE_CA_CERTas variables and restarts the app once they are ready. - Push to ship. From now on, every push to that branch deploys a new version, and you can roll back to an earlier one.
Prefer to say it in a sentence? On Home, type something like "Deploy my Next.js repository with a Plexivo Postgres database" into the Plexivo AI box and choose Plan my app. Plexivo AI prepares a plan with its price, and nothing runs until you choose Approve & deploy.
How do I connect Next.js to PostgreSQL on the server?
Create one pool for the whole server process and reuse it, rather than opening a connection for every request. Point the client at the CA certificate so it can verify the database it is talking to:
import pg from 'pg';
const pool = new pg.Pool({
connectionString: process.env.DATABASE_URL,
ssl: { ca: process.env.DATABASE_CA_CERT },
max: 10
});Import this pool only from server code: route handlers, server actions and server components. Each size has a connection limit, and with several app instances that limit is shared between them, so keep max modest. The smallest size allows 50 connections. On Business and Enterprise, a built-in PgBouncer pooler in transaction mode lets many more clients share them. See connect to Plexivo Postgres.
How do I keep the connection string secret in Next.js?
Next.js has one rule that protects you: only variables whose names start with NEXT_PUBLIC_ reach the browser. Give the database URL and any secret key ordinary names, and they stay on the server.
Plexivo adds three more protections:
- Encrypted, masked variables. Values on the Environment tab are encrypted at rest. Keys that look like secrets, such as
DATABASE_URL, stay masked until you choose Show, and each read is recorded in the audit log. - Plexivo Secrets for shared keys. Keep API keys you share across apps in Plexivo Secrets. On the Environment tab, in Secrets, choose Attach a secret…, pick it and choose Attach. When you change the secret, the app picks up the new version.
- Rotation without copying. When the database password rotates, the connected variables follow. You never paste a password by hand.
To add your own variables, choose + Add variable, enter the Key and Value, then Add and apply. Plexivo restarts the instances onto the new values one at a time, and each old instance keeps serving until its replacement is ready. Read environment and secrets.
Using the Plexivo Postgres Data API with Next.js
If you want sign-in and live updates without writing an API layer, turn on the Data API for your database and install the client:
npx create-next-app@latest notes
cd notes
npm install @plexivo/clientSet NEXT_PUBLIC_PLEXIVO_DATA_URL and NEXT_PUBLIC_PLEXIVO_PUBLISHABLE_KEY for the browser, and PLEXIVO_DATA_URL and PLEXIVO_SECRET_KEY for the server. Then create one client for the whole app:
import { createClient } from '@plexivo/client';
export const db = createClient(
process.env.NEXT_PUBLIC_PLEXIVO_DATA_URL,
process.env.NEXT_PUBLIC_PLEXIVO_PUBLISHABLE_KEY
);With row-level security on your tables, each signed-in user sees only their own rows, and a Realtime channel delivers every change the user may read. The secret key belongs only in route handlers. If it ever reaches a browser, the client refuses to start, and the Data API refuses any request that carries it from a web page. The full notes app, with sign-in, a live list and a SQL report route, is in the React and Next.js guide.
Build minutes, sleep and custom domains
Each build uses build minutes: the started minutes of fetching your code, building and pushing the image. Time waiting in the queue is never billed. Developer includes 100 build minutes a month and Startup 500. A .dockerignore that leaves out node_modules, test data and build output keeps every build smaller and quicker.
On Developer, an app that has served no request for 15 minutes sleeps and wakes on the next request. On Startup and above, apps stay on. When you are ready for your own domain, open the app's Domains tab and choose Add domain; Plexivo issues and renews the certificate. See custom domains and the pricing page for every limit.
FAQ
Can I host a Next.js app in India with a database?
Yes. Plexivo App Runner runs your Next.js app in Mumbai, and Plexivo Postgres runs beside it in the same region. Put both in one project and they connect over the private network.
Do I need a Dockerfile to deploy Next.js?
No. Without one, Plexivo detects your framework, installs dependencies, builds and sets the start command. Add a Dockerfile at the repository root when you want full control over the build.
Which port should my Next.js app listen on?
The one in the PORT environment variable, on 0.0.0.0; it is 8080 unless your image declares another. The Next.js production server reads PORT, so a standard app works without changes.
Where should I store my database password?
Let Plexivo deliver it. Connecting the database on the Environment tab gives your app DATABASE_URL, which is encrypted at rest, masked in the console and updated when the password rotates. Never give it a NEXT_PUBLIC_ name.
What does a small Next.js app with a database cost?
The smallest Plexivo App Runner size is US$6.04 a month and the smallest Plexivo Postgres size is US$11.98 a month, plus your plan. Indian customers pay in rupees by UPI, card or net banking, with a GST tax invoice. More on paying in rupees is in our guide to deploying from Git in India.
Ship your Next.js app
Connect your repository at cloud.plexivo.io and watch your first build on the Deployments tab. The free trial is on the Developer plan, and no credit card is required.