0

i am new at JS and Node. I am trying to make a task list in Expressjs. I have a bookshlef.js ODM. I traing to get all tasks from DB in function getAllTasks :

module.exports.getAllTasks = async function () {
let result = await  Task.fetchAll();
result = result.toJSON();
console.log(result);
}

and it print all data in console, but if I am trying to return data from function getAllTasks

module.exports.getAllTasks = async function () {
let result = await  Task.fetchAll();
result = result.toJSON();
return(result);
}

I get

Promise { <pending> }

I call it

var tasks = Application.getAllTasks();
console.log(tasks);

How can i return in getAllTasks a object with all data?

  • 1
    Try this `var tasks = await Application.getAllTasks();` or `Application.getAllTasks().then(tasks => {console.log(tasks)})`. Also in `getAllTasks` change `return(result)` to `return result`. – Nithish Sep 04 '20 at 16:39
  • @Nithish thanks. This way `Application.getAllTasks().then(tasks => {console.log(tasks)})` return object. – dkrakowski Sep 04 '20 at 18:00

0 Answers0