0

It states here that it's not a good practice to connect to a heroku db using a URL like this:

postgres://$user:$pass@$db_host.com:5432/$db_name

But you should rather "fetch the database URL config var from the corresponding Heroku app when your application starts" like this:

DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app) your_process

I want to connect to a heroku db from an external (outside heroku) node server using sequelize. How should I do that?

const db = new Sequelize(DATABASE_URL, {
  logging: false,
  pool: {
    max: 15,
    min: 5,
    idle: 10000,
    acquire: 10000,
  },
  dialectOptions: {
    ssl: {
    require: true,
  },
 },
 ssl: true,
});

1 Answer 1

1

With Heroku CLI, you would use heroku config:get DATABASE_URL. To do the same thing programmatically, consult the Heroku documentation which states:

You can manage your app’s config vars programmatically with the Heroku Platform API using a simple HTTPS REST client and JSON data structures. You need a valid Heroku access token representing a user with proper permissions on the app.

The details of REST API for config vars is described in the platform API reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.