Connecting to a database
How to wire a managed database connection string into your app safely.
Once you've provisioned a managed database, connecting your app is the same regardless of engine: copy the connection string into your app's environment and use it from your code.
1. Copy the connection string
Open the database in the dashboard and copy its connection string. It contains the username, password, host, port and database name.
2. Add it as an environment variable
In your app's Environment tab, add the connection string as a secret variable —
DATABASE_URL is a common name.

3. Use it in your code
Read the variable from the environment (for example process.env.DATABASE_URL) and
pass it to your database client. See the per-engine pages for code snippets:
External access
Your app and database run on the same platform, so internal connections are fast. If you need to reach the database from outside (for example a local migration tool), use the connection details shown on the database page.
Treat connection strings as secrets. Don't commit them to GitHub or print them in build logs.