Neon and Koyeb

Integrate a serverless Neon Postgres database to your application and benefit from native autoscaling, automatic HTTPS (SSL), auto-healing, and global load-balancing across our edge network with zero configuration.

Neon is a lightning-fast, cost-efficient, and easy-to-use serverless Postgres-compatible database provider. Not only a simple database provider, Neon can also be natively integrated into modern development workflows thanks to data branching which instantly deploys environments with an up-to-date copy of your production data.

This guide explains how to connect a Neon Postgres database to an application running on Koyeb. To successfully follow this documentation, you will need to have:

  • A Koyeb account to deploy the application. You can optionally install the Koyeb CLI to deploy the application from the command line
  • A Neon account to deploy the PostgreSQL database

The application that connects to the Neon PostgreSQL database uses Prisma as an ORM. Prisma is an open-source ORM. We use it to synchronize our database schema with our Prisma schema.

If you already have a freshly created Neon database running and want to quickly preview how to connect your Neon database to an application running on Koyeb, use the Deploy to Koyeb button below.

Deploy to Koyeb

Make sure to replace the DATABASE_URL environment variable with the connection string of your Neon database.

Create a Neon serverless PostgreSQL database

To create a Neon PostgreSQL database, sign into your Neon account.

On the Neon control panel, start by clicking the Create a project button to access the database creation page.

  1. Name your database, e.g., neon-koyeb
  2. Select the Postgres version to use for the database. Here, we use Postgres 15
  3. Pick the Region to run the database in. Here, we use Europe (Frankfurt) as our compute will be deployed in this region on Koyeb

When you are done configuring your database, click the Create project button. Your database will be provisioned.

A modal will pop up with your connection string. Store this value in a safe place, we will use it later.

The connection string should be similar to the following:

postgres://<user>:<password>@<host>:<port>/neondb

Deploy the application on Koyeb

You can deploy on Koyeb using the control panel or via the Koyeb CLI.

Via the Koyeb control panel

To deploy the example application using the control panel, follow these steps:

  1. Create a new Koyeb App
  2. Setgithub.com/koyeb/example-express-prisma as the GitHub repository to deploy and keep the default branch main
  3. Set npm run postgres:init as the Build command
  4. Add a DATABASE_URL environment variable to indicate the application how to connect to the Neon Postgres database. Give the environment variable a name, DATABASE_URL and enter the connection string from earlier as the value
  5. Name your service, for instance express-neon
  6. Click the Deploy button

Koyeb is now building the application. Once the build has finished, you will be able to access your application running on Koyeb by clicking the URL ending with .koyeb.app.

The example application exposes a /planets endpoint that you can use to list planets from the database. Once your deployment is live, you should see the following results when navigating to https://<YOUR_APP_URL>.koyeb.app/planets:

[ { "id": 1, "name": "Mercury" }, { "id": 2, "name": "Venus" }, { "id": 3, "name": "Mars" } ]

Via the Koyeb CLI

To deploy the example application using the Koyeb CLI, run the following command in your terminal:

koyeb app init express-neon \ --git github.com/koyeb/example-express-prisma \ --git-branch main \ --git-build-command "npm run postgres:init" \ --ports 8080:http \ --routes /:8080 \ --env PORT=8080 \ --env DATABASE_URL="postgres://<user>:<password>@<host>:<port>/neondb"

Make sure to replace user, password, host and port with your own.

Access deployment logs

To track the app deployment and visualize build logs, execute the following command:

koyeb service logs express-neon/express-neon -t build

Access your app

Once the deployment of your application has finished, you can retrieve the public domain to access your application by running the following command:

$ koyeb app get express-neon ID NAME DOMAINS CREATED AT ec6a4311 express-neon ["express-neon-myorg.koyeb.app"] 24 Jan 23 11:12 UTC

The example application exposes a /planets endpoint that you can use to list planets from the database. Once your deployment is live, you should see the following results when navigating to https://<YOUR_APP_URL>.koyeb.app/planets:

[ { "id": 1, "name": "Mercury" }, { "id": 2, "name": "Venus" }, { "id": 3, "name": "Mars" } ]

Delete the example application and Neon database

To delete the example application and the Neon PostgreSQL database and avoid incurring any charges, follow these steps:

  • From the Neon dashboard, click Settings for the database and click Delete project. Follow the instructions.
  • From the Koyeb control panel, select the App to delete. Under the Settings tab, click the Delete button and follow the instructions.