All articles
Deployment·10 min read

Deploy Next.js with PostgreSQL on Helicarrier.

A tested GitHub-to-deployment walkthrough: build a Next.js app, connect PostgreSQL privately, run a release migration, and verify the result.

Helicarrier team · · Updated

Deploy Next.js with PostgreSQL on Helicarrier.

By the end of this guide, you will have a Next.js application reading four sample records from a PostgreSQL database on Helicarrier. You will deploy the code from GitHub, connect the database without copying its password, and run a schema migration before releasing the application.

The example is a small launch board. Its records are fictional, and its public page only reads data. It has no login or public write endpoint, which makes it a useful disposable deployment exercise.

Verified on the live platform. This walkthrough uses Next.js 16.4.2, Node.js 22, node-postgres 8.23.1, and PostgreSQL 16. Screenshots show the optional new dashboard interface. If your workspace shows the classic interface, use its switch to the new experience; the underlying services and settings are the same. A build passing is only the first check—we also verify the database, migration, and running page.

Before you start

  • A Helicarrier workspace with permission to create a project, a web service, and a database.
  • A GitHub account and a copy of the launch-board example repository. Fork it into your account, then make sure Helicarrier’s GitHub connection can access that repository.
  • A disposable project. The screenshots use Helicarrier Tutorials Demo; use your own project and keep existing production data separate.

We used Heli S1 for the app and Heli DB-S1 for PostgreSQL: 512 MB of memory each, with 2 GB of database storage. Standard full-month reference rates are $3 for the app and $3.50 for the database, before optional add-ons. The screenshots show the account’s NGN estimate. Review your current dashboard prices before creating anything; these figures are not a quote for your account or a production sizing recommendation. Compare the PostgreSQL plans and storage costs, or see all platform pricing.

1. Create the database

Open your project and select an environment. This demo uses its default environment, named Production; it contains only tutorial resources. Select New service → Database → PostgreSQL.

Name it tutorial-postgres, select PostgreSQL 16, set the database name to helicarrier_guide, and use guide as the username. Leave the password blank so Helicarrier generates one. This application does not need any optional extensions.

PostgreSQL setup with the demo database name and an empty password field for automatic generation
Create a separate database for the example. No database password is shown or needed in this guide. Select the image to view it at full size.

Choose Heli DB-S1 with 2 GB of storage. We left the optional daily-backup add-on off for this short-lived exercise. For an application you intend to keep, review the backup and restore policy and choose an appropriate backup plan.

Select Provision. The new dashboard stages the change on the canvas; select Apply to create the database. Wait until its status is active. Keep external database access off: the application will use a private service reference.

2. Deploy the application from GitHub

In the same project and environment, choose New service → GitHub repository. Select your copy of the example and its main branch. Use these settings:

SettingValue
Nametutorial-launch-board
Service typeWeb service
Internal port3000
Root directoryLeave blank for the standalone example repository
Build strategyAuto, which detects the included Dockerfile
Install, build, and start commandsLeave blank; the Dockerfile defines them
Release commandLeave blank for this first deployment
PlanHeli S1
GitHub repository configuration showing the main branch, web service type, and internal port 3000
The example builds from a Git repository. Your repository owner and visibility may differ from this screenshot. Select the image to view it at full size.

Select Create & deploy, then Apply on the canvas. Follow the deployment until the web service is active. Its generated URL may initially show Setup needed; that is expected before the connection and migration are applied. At this stage /health returns HTTP 503.

The Dockerfile builds a standalone Next.js server, binds it to 0.0.0.0:3000, and runs it as a non-root user. The build does not need a database. Keep the default read-only filesystem enabled; this application stores its data in PostgreSQL.

3. Connect PostgreSQL with a reference

Open the application service, then Variables & secrets. Select Reference a variable from another service. Choose tutorial-postgres as the source, Connection URL as the value, and DATABASE_URL as the variable name. Select Add reference.

The app’s Variables and secrets panel showing DATABASE_URL linked to tutorial-postgres through an internal URL
The dashboard displays the reference relationship without exposing the database credentials. Select the image to view it at full size.

A reference resolves the provider’s current connection details when the app deploys. Do not add a second manual DATABASE_URL, paste a password into GitHub, or enable external access for this connection. Do not use NEXT_PUBLIC_DATABASE_URL: variables with that prefix can be included in browser code.

The example uses a server-side connection pool with a maximum of five connections. Each page request reads from PostgreSQL; the browser receives the displayed records, not the connection string. Learn more about service references.

4. Run the migration during release

Open the app’s Service settings. Under Build settings, choose Force Dockerfile, set the Dockerfile path to Dockerfile, and set the Release command to:

Release command
npm run db:migrate
Service settings showing npm run db:migrate as the release command and the read-only filesystem enabled
The migration command runs from the newly built image before traffic switches to it. Select the image to view it at full size.

Select Save & redeploy. In Deployments, follow the new release. The migration creates guide_launches, inserts four fictional records, and records the migration in guide_migrations. Successful logs include:

Expected release log messages
Running release command: npm run db:migrate
Database migrations applied. The launch board is ready.
Release command succeeded.

The migration runs inside a transaction and takes an advisory lock so overlapping releases do not apply it twice. Subsequent releases skip recorded migrations. This is a small teaching example, not a complete migration framework. Add a new migration file for later schema changes rather than editing an already-applied file.

An application rollback changes the running code; it does not undo a database migration. For real applications, use backward-compatible schema changes, test on separate data, and establish a restore path before risky migrations.

5. Verify the result, then monitor it

Open the generated URL shown in the app’s service overview. You should see PostgreSQL connected and four rows, including “Give the idea a home” and “Connect the data layer.” Refresh the page to confirm it still reads the database.

The deployed Next.js launch board showing PostgreSQL connected and four fictional records
The actual deployed application, reading its records from the managed database. Select the image to view it at full size.

Check the readiness endpoint, replacing the placeholder with the exact URL from your dashboard:

Verify database readiness
curl --fail https://YOUR-SERVICE.on.helicarrier.xyz/health
# Expected: {"ok":true}

This endpoint returns HTTP 200 only when it can query the application table. An HTTP 200 response from the homepage alone is not enough: its setup screen deliberately renders even when the database is not ready.

Under Service settings → Health checks & auto-recovery, enable Automatic health checks, set the health path to /health, keep the interval at 30 seconds and the failure threshold at 3, then save that section. These checks can restart the app after consecutive failures; they cannot repair a broken database or migration.

Finally, deploy the same code again. The release command should succeed, /health should return OK, and the board should still contain four rows. This checks that the release is repeatable, not just that the first migration worked.

The live app and PostgreSQL service, both active, connected by a DATABASE_URL reference
The completed demo stack on the project canvas. Select the image to view it at full size.

If a step fails

  • Repository missing: check the selected GitHub account and whether the existing Helicarrier GitHub connection can access your example repository.
  • Build succeeds but the service cannot start: confirm the internal port is 3000 and clear any start-command override. The included image supplies its own start command.
  • Setup needed or HTTP 503: confirm PostgreSQL is active, the app has the reference named exactly DATABASE_URL, and you deployed after adding it. Then look for a successful release command.
  • Migration fails: inspect the release logs and verify the reference and database status. Fix the cause and redeploy. Do not delete an existing database as a troubleshooting shortcut.
  • Memory pressure: review Metrics and runtime logs before changing plans. The small plan used here is for a light demonstration, not an estimate for your production workload.

When asking for support, share the failing step and a sanitized error. Keep passwords, connection strings, and API keys out of screenshots and messages.

Clean up, or keep building

If this was a disposable exercise, remove the example app and its database through each service’s Service settings → Remove service action. Verify the names before confirming, and check that only the tutorial resources were removed. Export any data you want to keep first.

If you are keeping the application, review backups, capacity, and access before using real data. Add a custom domain when you are ready. To investigate deployments through your coding agent, continue with the MCP guide; for exact build options, use the build and runtime reference.

Keep exploring

Another useful next step.

Ready when you are

Make something.
We’ll keep it running.

Bring your code. Give your next idea a home on Helicarrier Cloud.