I'm using Sequelize with node.js and the express framework.
I need to implement a function in my app-module which provides specific information from the database. My current approach is this:
var app = express();
app.provide = function(){
models.Project.findAll({ include: [{ all: true}]}).then(function(data){
return data;
});
};
module.exports = app;
My problem is the query runs asynchronous and the provide function returns an "undefined" before the query finished. If the return statement is not in the callback it works as expected, but there I don't have any data:
var app = express();
app.provide = function(){
models.Project.findAll({ include: [{ all: true}]}).then(function(data){
});
return "test";
};
module.exports = app;
Is it even possible to return data from the database like this?
Thanks in advance!