I'm trying to get all authors and books from database in SailsJS using following code:
module.exports = {
all: function(req, res) {
let title = 'All Authors'
let authors = Author.find({}).then(function(results){ return results })
let books = Book.find({}).then(function(results){ return results })
sails.log(authors)
}
}
I'm getting following output:
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
I feel like the sails.log
function is running before Promise completion. Guide me how to return values from Promise.