Integrations
Databases
Neon

Neon and Koyeb

Neon (opens in a new tab) is a lightning-fast, cost-efficient, and easy-to-use serverless PostgreSQL-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 PostgreSQL database to an application running on Koyeb. To successfully follow this documentation, you will need to have:

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 (opens in a new tab)

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 in to your Neon account (opens in a new tab).

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 PostgreSQL 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.

To deploy the example application (opens in a new tab) using the control panel (opens in a new tab), follow these steps:

  1. Click Create Web Service on the Overview tab of the Koyeb control panel.
  2. Select GitHub as the deployment option.
  3. Set github.com/koyeb/example-express-prisma as the GitHub repository to deploy.
  4. Expand the Builder section. Click the override toggle associated with the Build command and enter npm run postgres:init in the field.
  5. Expand the Environment variables section. Add a DATABASE_URL environment variable to tell the application how to connect to the Neon PostgreSQL database. Give the environment variable the name DATABASE_URL and enter the connection string from earlier as the value.
  6. Name your App and Service, for instance express-neon.
  7. Click the Deploy button.

A Koyeb App and Service will be created. Your application will be built and deployed to Koyeb. 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"
  }
]

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: