TypeError: Cannot read property \'findAll\' of undefined (expressjs).
All functions (sequelize) are not working. All errors: Cannot rea
Your model/index.js
looks fine. In your controller try findAll()
method inside sequelize.sync().then(function () {
Here is my approach to the problem
nb: instead of
models/index.js
i have a similardb.js
file inside config folder which having the dbconnection scripts and sequelize object.
My userController.js will look like (working code) :
var db = require('./../config/db'),
seq = db.seq,
Sequelize = db.Sequelize;
module.exports = function(app) {
app.get('/getUsers',function(req,res){
var Users = require('../models/UserModel')(app); //since i am binding to a single object - app
seq.sync().then(function () {
Users.findAll({
attributes: ['usr_code', 'usr_name']
}).then(function (users) {
users.forEach(function(user,index,arr){
console.log(user.usr_code);
});
});
});
});
}
Hope this helps you. :)