Sequelize - Test database connection

By xngo on September 4, 2022

const { Sequelize } = require('sequelize');
 
// Connect to database.
const sequelize = new Sequelize({
    dialect: 'sqlite',
    storage: 'C:/myDataFile.sqlite'
});
 
// Test connection
try {
    sequelize.authenticate();
    console.log('Connection has been established successfully.');
} catch (error) {
    console.error('Unable to connect to the database:', error);
}

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.