How to connect to another app (like a database)

Apps inside the same stack can communicate with each other using the Internal Name advertised inside the settings :

You can use this internal name inside Environment variables (recommended), configuration files, or inside your app code.

For MySQL, this internal name replaces the value “localhost” you may use to see on old-school hosting providers.

Datastores (databases, Redis, etc…) cannot communicate to the outside world so the internal name is your only way to reach the database from inside your stack.

Specify the database local port

Some databases like Redis require that the local port be mentioned inside the connection string.

We recommend the use of environment variables to connect to local databases. Here are some examples:

Postgres

DATABASE_URL=postgres://<user>:<password>@<internal_name>:5432/<database>

Redis

REDIS_URL=redis://<internal_name>:6379

Note: Redis doesn’t require a user to be provided in the connection string.

RabbitMQ

<internal_name>:5672
RabbitMQ Management Interface is available using the web address of your app.

Was this helpful?

1 / 13