Can't connect to heroku postgresql database from local node app with sequelize
OK, found the answer by browsing sequelize source code : https://github.com/sequelize/sequelize/blob/master/lib/dialects/postgres/connection-manager.js#L39
To activate SSL for PG connections you don't need native: true
or ssl: true
but dialectOptions.ssl: true
so the following did finally work:
sequelize = new Sequelize(process.env.DATABASE_URL, {
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: true
}
});
You no longer need to parse the DATABASE_URL env variable, there is a Sequelize constructor which accepts the connection URL:
sequelize = new Sequelize(process.env.DATABASE_URL, {
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: true
}
});
One needs to add dialectOptions under ssl
"development": {
"username": process.env.DB_USERNAME,
"password": process.env.DB_PASSWORD,
"database": process.env.DB_NAME,
"host": process.env.DB_HOST,
"dialect": process.env.DB_DIALECT,
"dialectOptions": {
ssl: {
require: true,
rejectUnauthorized: false
}
}
},
Source is as per official sequelize github