Can't Connect To Heroku Postgresql Database From Local Node App With Sequelize


Answer :

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


Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?