Sequelize - Decouple into multiple files

By xngo on September 10, 2022

// [] database.js
const { Sequelize } = require("sequelize");
 
module.exports.sequelize = new Sequelize({
    dialect: 'sqlite',
    storage: 'database.sqlite'
});
// [] main.js
const {sequelize} = require('./database');
 
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.