const Sequelize = require('sequelize');
const path = 'mysql://user12:12user@localhost:3306/testdb';
const sequelize = new Sequelize(path, { operatorsAliases: false });
sequelize.authenticate().then(() => {
console.log('Connection established successfully.');
}).catch(err => {
console.error('Unable to connect to the database:', err);
}).finally(() => {
sequelize.close();
});
// Include Sequelize module
const Sequelize = require('sequelize')
// Creating new Object of Sequelize
const sequelize = new Sequelize(
'DATABASE_NAME',
'DATABASE_USER_NAME',
'DATABASE_PASSWORD', {
// Explicitly specifying
// mysql database
dialect: 'mysql',
// By default host is 'localhost'
host: 'localhost'
}
);
// Exporting the sequelize object.
// We can use it in another file
// for creating models
module.exports = sequelize