say i have the following modelConfiguration.js file:
const Sequelize = require('sequelize');
const dbConfig = require('../config/database.config');
module.exports = function () {
const sequelize = new Sequelize(dbConfig.database, dbConfig.user, dbConfig.password, {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
});
const employee = sequelize.define('employee', {
id:{
type: Sequelize.DataTypes.INTEGER,
primaryKey: true
},
token: Sequelize.DataTypes.TEXT
});
return sequelize;
};
Now here as you can see i return the sequelize object.
Now i wish to set a variable equal to the object returned so in my server.js i do the following:
const seq = require('./models/modelConfig');
However this does not work.
Can anyone tell me what ive done wrong? (Maybe ive misunderstood something)
module.exportsreturns a function that when called returns thatSequelizeinstance.const seq = require('./models/modelConfig')();This is what you should do.