Search code examples
herokuloopbackjsheroku-postgres

How do I use env.DATABASE_URL with Loopback in Heroku?


I've removed datasources.json and added a datasources.local.js file.

var postgresURI = process.env.DATABASE_URL; module.exports = { db: { defaultForType: 'postgresql', connector: 'postgresql', url: postgresURI } };

In model-config.json I have "dataSource": "db" set for all sections.

It throws the following error: User is referencing a dataSource that does not exist: "db".

I understand the error but not why it's being thrown. What I am doing wrong?


Solution

  • As documentation says:

    You can override values set in datasources.json in the following files: datasources.local.js or datasources.local.json

    So instead of removing datasources.json you might want to keep it with a declaration of "db" in it. While in "datasources.local.js" you need to override environment specific setting which is the url.