Postgres connect to database with URL
Published on
Last updated on
2 min read • --- views
Very often, cloud database services such as neon.tech allow you to connect via URL.
That is, without credentials such as user
, password
, etc.
Connection details
Connection URL
It's official PostgreSQL format for connection URLs

Base URL and path
Here's an example of a base URL and path structure using uppercase placeholder values:
postgresql://USER:PASSWORD@HOST:PORT/DATABASE

How this site connects to the database
Store your credentials in .env
Store your credentials in your .env
file.
PGHOST='<endpoint_hostname>:<port>'
PGDATABASE='<dbname>'
PGUSER='<username>'
PGPASSWORD='<password>'
ENDPOINT_ID='<endpoint_id>'
where:
endpoint_hostname
the hostname of the branch endpoint. The endpoint hostname has an ep- prefix and appears similar to this: ep-tight-salad-272396.us-east-2.aws.neon.techdbname
is the name of the database. The default Neon database is neondbuser
is the database userpassword
is the database user's password, which is provided to you when you create a projectendpoint_id
is the ID of the branch endpoint that you are connecting to. The endpoint_id has an ep- prefix and appears similar to this: ep-tight-salad-272396
Use prisma.io to connect Postgres
// You can create DATABASE_URL in your code
const DATABASE_URL = `postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}/${PGDATABASE}`;
# Or better to use .env file
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
Use Datagrip to connect Postgres
You can use same credentials like HOST
, PORT
, USER
, PASSWORD
, DATABSE
for connection to Database with
DataGrip.

You might also like:
Conventional Commits
--- views
Discover how Conventional Commits can enhance your work and project's readability.
Why Are JavaScript Naming Conventions Important?
--- views
Master JavaScript naming conventions with this comprehensive guide. Learn best practices for naming variables, functions, classes, and more to write cleaner, more maintainable code.
How to decrease deployment time by 44% with pnpm
--- views
Learn how to efficiently migrate your project from npm to pnpm with this guide.
Share it: