Use Neon as your dev environment for AWS RDS: accelerate your workflow while reducing costs
Getting Started

Connecting Neon to your stack

Learn how to integrate Neon into your application

Using Neon as the serverless database in your tech stack means configuring connections. Whether it’s a direct connection string from your language or framework, setting environment variables for your deployment platform, connecting to ORMs like Prisma, or configuring deployment settings for CI/CD workflows, it starts with the connection.

Connecting to your application

This section provides connection string samples for various frameworks and languages, helping you integrate Neon into your tech stack.

psql
.env
Next.js
Drizzle
Prisma
Python
Ruby
Rust
Go
# psql example connection string
psql postgres://username:password@hostname:5432/database?sslmode=require

Obtaining Connection Details

When connecting to Neon from an application or client, you connect to a database in your Neon project. In Neon, a database belongs to a branch, which may be the default branch of your project (main) or a child branch.

You can obtain the database connection details you require from the Connection Details widget on the Neon Dashboard. Select a branch, a compute, a database, and a role. A connection string is constructed for you.

Connection details widget

Neon supports pooled and direct connections to the database. Use a pooled connection string if your application uses a high number of concurrent connections. For more information, see Connection pooling.

A Neon connection string includes the role, password, hostname, and database name.

postgres://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname
           ^    ^         ^                                               ^
     role -|    |         |- hostname                                     |- database
                |
                |- password

note

The hostname includes the ID of the compute, which has an ep- prefix: ep-cool-darkness-123456. For more information about Neon connection strings, see Connection string.

Using Connection Details

You can use the details from the connection string or the connection string itself to configure a connection. For example, you might place the connection details in an .env file, assign the connection string to a variable, or pass the connection string on the command-line.

.env file

PGUSER=alex
PGHOST=ep-cool-darkness-123456.us-east-2.aws.neon.tech
PGDATABASE=dbname
PGPASSWORD=AbC123dEf
PGPORT=5432

Variable

DATABASE_URL="postgres://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname"

Command-line

psql postgres://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname

note

Neon requires that all connections use SSL/TLS encryption, but you can increase the level of protection by appending an sslmode parameter setting to your connection string. For instructions, see Connect to Neon securely.

FAQs

Where do I obtain a password?

It's included in your Neon connection string, which you can find on the Neon Dashboard, in the Connection Details widget.

What port does Neon use?

Neon uses the default Postgres port, 5432.

Network Protocol Support

Neon supports both IPv4 and IPv6 addresses.

Additionally, Neon provides a serverless driver that supports both WebSocket and HTTP connections. For further information, refer to our Neon serverless driver documentation.

Connection Notes

  • Some older client libraries and drivers, including older psql executables, are built without Server Name Indication (SNI) support and require a workaround. For more information, see Connection errors.
  • Some Java-based tools that use the pgJDBC driver for connecting to Postgres, such as DBeaver, DataGrip, and CLion, do not support including a role name and password in a database connection string or URL field. When you find that a connection string is not accepted, try entering the database name, role, and password values in the appropriate fields in the tool's connection UI

Last updated on

Edit this page
Was this page helpful?