As of latest version of Sequelize (i.e. 3.3.2
), authenticate
can be used to check the connection:
var sequelize = new Sequelize("db", "user", "pass");
sequelize.authenticate().then(function(errors) { console.log(errors) });
authenticate
simply runs SELECT 1+1 AS result
query to check the db connection.
UPDATE:
Errors by the newest API need to be handled in catch
:
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
UPDATE 2:
I haven’t tested this, but its only logical that the same thing can be reached with async/await
:
try {
await sequelize.authenticate()
} catch (err) {
console.error('Unable to connect to the database:', err)
}